#include #include #include #include using namespace std; const int Nmax = 102 * 102; const int inf = INT_MAX; vector G[Nmax]; int MAT[102][102]; int top_sort[Nmax]; int viz[Nmax]; long long path_max[Nmax]; long long maxim_gen = -inf; int T, N, M, Nodes; void DFS( int nod ) { viz[nod] = 1; for ( int i = 0; i < G[nod].size(); ++i ) if ( !viz[ G[nod][i] ] ) DFS( G[nod][i] ); top_sort[ ++top_sort[0] ] = nod; } void solve() { for ( int i = 1; i <= Nodes; i++ ) { int nod = top_sort[i]; for ( auto x: G[nod] ) { path_max[nod] = max( path_max[nod], path_max[x] + 1 ); } maxim_gen = max( maxim_gen, path_max[nod] ); } } int main() { ///ifstream cin("date.in"); cin >> N >> M; Nodes = 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; } } for ( int i = 1; i <= N; ++i ) { for ( int j = 1; j <= M; ++j ) { if ( MAT[i][j] == 0 ) { continue; } int nod = M * ( i - 1 ) + j; int ii, jj; ii = i; jj = j + 1; if ( MAT[ii][jj] == 1 ) { int vecin = M * ( ii - 1 ) + jj; G[nod].push_back( vecin ); } ii = i + 1; jj = j; if ( MAT[ii][jj] == 1 ) { int vecin = M * ( ii - 1 ) + jj; G[nod].push_back( vecin ); } } } DFS( 1 ); solve(); cout << maxim_gen + 1 << "\n"; return 0; }