#include<iostream>
using namespace std;

#define MaxN 110

int N,M,Sol;
int Best[MaxN][MaxN],C[MaxN][MaxN];
char S[MaxN][MaxN];

void dinamica(void)
{
    if(S[1][1] == '&')
        return ;

    Best[1][1] = 1;

    for(int i=1;i<=N;i++)
        for(int j=1;j<=M;j++)
            if(S[i][j] == '.' && (Best[i-1][j] || Best[i][j-1]))
            {
                Best[i][j] = max(Best[i-1][j],Best[i][j-1]) + 1;
                Sol = max(Sol,Best[i][j]);
            }
}

int main()
{
    cin >> N >> M;
    for(int i=1;i<=N;i++)
        cin >> (S[i]+1);

    dinamica();

    cout << Sol << "\n";
}