#include #define mp make_pair using namespace std ; const int NR = 100005 ; int n , m , a [ 105 ][ 105 ] , d [ 105 ][ 105 ] , sol = 1 ; //ifstream in ("date.in") ; string s ; int main () { int i , j ; cin >> n >> m ; for ( i = 1 ; i <= n ; ++ i ) { cin >> s ; for ( j = 1 ; j <= m ; ++ j ) { if ( s [ j - 1 ] == '&' ) a [ i ][ j ] = 1 ; } } // if ( a [ i ][ j ] == 1 ) return cout << 0 , 0 ; queue < pair < int , int > > q ; pair < int , int > nod ; q.push( mp ( 1 , 1 ) ) ; d [ 1 ][ 1 ] = 1 ; while ( !q.empty() ) { nod = q.front() ; q.pop() ; i = nod.first ; j = nod.second ; if ( j + 1 <= m && !a [ i ][ j + 1 ] && d [ i ][ j + 1 ] < d [ i ][ j ] + 1 ) { d [ i ][ j + 1 ] = d [ i ][ j ] + 1 ; q.push( mp ( i , j + 1 ) ) ; } if ( i + 1 <= n && !a [ i + 1 ][ j ] && d [ i + 1 ][ j ] < d [ i ][ j ] + 1 ) { d [ i + 1 ][ j ] = d [ i ][ j ] + 1 ; q.push( mp ( i + 1 , j ) ) ; } sol = max ( sol , d [ i ][ j ] ) ; } cout << sol ; // for ( i = 1 ; i <= n ; ++ i , cout << '\n' ) // for ( j = 1 ; j <= m ; ++ j ) cout << d [ i ][ j ] << ' ' ; }