#include #include #define nmax 101 using namespace std; int sol[nmax][nmax]; queue < pair > q; int main() { int N, M; scanf ("%d %d", &N, &M); int A[nmax][nmax], i, j, x, y, max; char c; for (i = 1; i <= N; ++i) { scanf ("%c", &c); for (j = 1; j <= M; ++j) { scanf ("%c", &c); if (c == '.') A[i][j] = 0; else A[i][j] = 1; } } for (i = 0; i <= N + 1; ++i) A[i][0] = 1, A[i][M+1] = 1; for (j = 0; j <= M + 1; ++j) A[0][j] = 1, A[N+1][j] = 1; q.push(make_pair(1,1)); max = 1; sol[1][1] = 1; while (!q.empty()) { x = q.front().first; y = q.front().second; q.pop(); if (A[x+1][y] == 0 && sol[x+1][y] < sol[x][y] + 1) { sol[x+1][y] = sol[x][y] + 1; q.push(make_pair(x+1,y)); if (sol[x+1][y] > max) max = sol[x+1][y]; } if (A[x][y+1] == 0 && sol[x][y+1] < sol[x][y] + 1) { sol[x][y+1] = sol[x][y] + 1; q.push(make_pair(x,y+1)); if (sol[x][y+1] > max) max = sol[x][y+1]; } } //if (A[1][1] == 1) // max = 0; printf ("%d", max); return 0; }