#include #include #include #include using namespace std; const int NMAX = 110, INF = 0x3f3f3f3f; int N, M, Best[NMAX][NMAX]; char Mat[NMAX][NMAX]; int main() { // freopen("b.in", "r", stdin); // freopen("b.out", "w", stdout); scanf("%i %i\n", &N, &M); for(int i = 1; i <= N; ++ i) gets(Mat[i] + 1); if(Mat[1][1] == '&') { printf("0\n"); return 0; } memset(Best, INF, sizeof(Best)); Best[0][1] = Best[1][0] = 0; for(int i = 1; i <= N; ++ i) for(int j = 1; j <= M; ++ j) if(Mat[i][j] != '&') { int Now = INF; if(Best[i][j - 1] != INF) Now = Best[i][j - 1]; if(Best[i - 1][j] != INF) { if(Now == INF) Now = Best[i - 1][j]; else Now = max(Now, Best[i - 1][j]); } Best[i][j] = 1 + Now; } int Ans = 0; for(int i = 1; i <= N; ++ i) for(int j = 1; j <= M; ++ j) if(Best[i][j] < INF) Ans = max(Ans, Best[i][j]); printf("%i\n", Ans); }