#include #include using namespace std; const int MAXN = 120; int n, m, used[MAXN][MAXN]; char c[MAXN][MAXN]; void dfs(int x, int y) { if (used[x][y]) return; used[x][y] = 1; if (x < n && c[x + 1][y] != '&') dfs(x + 1, y); if (y < m && c[x][y + 1] != '&') dfs(x, y + 1); } int main() { cin >> n >> m; cin.get(); for (int i = 1; i <= n; ++i) cin.getline(c[i] + 1, MAXN); dfs(1, 1); int rez = 0; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { if (used[i][j] && i + j - 1 > rez) rez = i + j - 1; } } cout << rez; return 0; }