#include #include #include #include using namespace std; const int Nmax = 102; const int dl[] = { 0, 1 }; const int dc[] = { 1, 0 }; int MAT[Nmax][Nmax]; int D[Nmax][Nmax]; int N, M; queue < pair > Q; int maxim = 1; int main() { ///ifstream cin("date.in"); cin >> N >> M; for ( int i = 1; i <= N; ++i ) { string s; cin >> s; for ( int j = 0; j < M; ++j ) { if ( s[j] == '.' ) MAT[i][j + 1] = 1; else MAT[i][j + 1] = 0; } } Q.push( make_pair( 1, 1 ) ); D[1][1] = 1; while ( Q.size() ) { int i = Q.front().first; int j = Q.front().second; Q.pop(); for ( int k = 0; k < 2; ++k ) { int ii = i + dl[k]; int jj = j + dc[k]; if ( D[ii][jj] == 0 && MAT[ii][jj] == 1 ) { D[ii][jj] = D[i][j] + 1; maxim = max( maxim, D[ii][jj] ); Q.push( make_pair( ii, jj ) ); } } } cout << maxim; return 0; }