#include <cstdio>

using namespace std;
char c[105][105];
int DP[105][105];
int N,M,sol;

int max(int a,int b){
    if(a < b)
        return b;
    return a;
}

void Read( void ){
    scanf("%d%d\n",&N,&M);
    for(int i = 1; i <= N; ++i)
        fgets(c[i]+1,105,stdin);
}

void Solve()
{
    if(c[1][1] == '&')
    {
        printf("0\n");
        return;
    }
    DP[1][1] = 1;
    for(int i = 1; i <= N; ++i)
        for(int j = 1; j <= M; ++j)
        {
            if(i == 1 && j == 1)
                continue;

            if(c[i][j] == '.')
            {
                if(c[i-1][j] == '.')
                    DP[i][j] = DP[i-1][j] + 1;
                if(c[i][j-1] == '.')
                    DP[i][j] = max(DP[i][j-1] + 1,DP[i][j]);
                sol = max(DP[i][j],sol);
            }
        }
    printf("%d\n",sol);
}

int main()
{
    ///freopen("run.in","r",stdin);
    Read();
    Solve();

    return 0;
}