#include <string> // std::string #include <iostream> // std::cout #include <sstream> #include <vector> using namespace std; int n; int m; vector<string> a; int sol = -1; int main() { string tmp; getline(cin, tmp); stringstream ss(tmp); ss >> n; ss >> m; for(int i=0; i<n; i++) { getline(std::cin, tmp); a.push_back(tmp); } int c[n][m]; for(int i=0; i<n; i++) for(int j=0; j<m; j++) c[i][j]=0; for(int i=0; i<n; i++) for(int j=0; j<m; j++) { c[i][j]=0; if (a[i][j] == '&') break; if (i > 0) if (c[i-1][j] + 1 > c[i][j] && a[i - 1][j] != '&') c[i][j] = c[i-1][j]+1; if (j > 0) if (c[i][j-1] + 1 > c[i][j] && a[i][j-1] != '&') c[i][j] = c[i][j-1]+1; if (c[i][j] > sol) sol=c[i][j]; } cout << sol + 1; return 0; } /* 4 4 ..&. ..&. ..&. ..&. */