#include <iostream>
using namespace std;
int n, m, best[110][110], sol;
char mat[110][110];

int main()
{
	int i, j;
	cin >> n >> m;
	for(i = 1; i <= n; ++i)
		cin >> (mat[i] + 1);
	if(mat[1][1] == '&')
	{
		cout << "0\n";
		return 0;
	}
	best[1][1] = sol = 1;
	for(i = 1; i <= n; ++i)
	{
		for(j = 1; j <= m; ++j)
		{
			if(i == 1 && j == 1)
				continue;
			if(mat[i][j] == '.')
			{
				if(mat[i - 1][j] == '.' && best[i - 1][j])
					best[i][j] = best[i - 1][j] + 1;
				if(mat[i][j - 1] == '.' && best[i][j - 1])
					best[i][j] = max(best[i][j], best[i][j - 1] + 1);
			}
			sol = max(sol, best[i][j]);
		}
	}
	cout << sol << "\n";
	return 0;
}