#include<iostream>
#include<algorithm>
#define NMAX 101
using namespace std;
short N,M;
char a[NMAX][NMAX];
int b[NMAX][NMAX],maxx=0;
void citire(){
     cin>>N;
     cin>>M;
     short i,j;
     for(i=1;i<=N;i++){
        for(j=1;j<=M;j++)
            cin>>a[i][j];
     }
     b[1][1]=1;
}
int rezolva(){
    short i,j;
    for(i=1;i<=N;i++){
        for(j=1;j<=M;j++){
            if(b[i][j] || a[i][j]=='&')
                continue;
            if(b[i-1][j] && a[i-1][j]!='&')
                b[i][j]=b[i-1][j]+1;
            if(b[i][j-1] && a[i][j-1]!='&')
                b[i][j]=max(b[i][j],b[i][j-1]+1);
            if(b[i][j]>maxx)
                maxx=b[i][j];
        }
    }
    return maxx;
}
int main(){
    citire();
    cout<<rezolva();
    return 0;
}