#include <iostream>
using namespace std;
int st[100][100];

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

int main(){
	int x, y;
	int mmax = 0;
	char c;
	cin>>y>>x;
//dp->f(x, y) = max(f(x-1, y), f(x, y-1))+1
	for(int y1=0; y1<y; y1++){
		for(int x1 = 0; x1<x; x1++){
			cin>>c;
			if(c=='&'){	st[x1][y1] = -10001;	}
			else{	
				if(x1 == 0 && y1 == 0) st[x1][y1] = 1;
				else if(x1 == 0)st[x1][y1] = st[x1][y1-1]+1;
				else if(y1 == 0)st[x1][y1] = st[x1-1][y1]+1;
				else st[x1][y1] = max(st[x-1][y], st[x1][y1-1])+1;
				if(st[x1][y1] > mmax)
					mmax = st[x1][y1];
			}
		}
	}
	cout<<mmax;
	return 0;

}