#include #include #include #include #include #include using namespace std; string s; int n, m, sol; bool a[105][105]; const int dx[2] = {1, 0}, dy[2] = {0, 1}; int d[105][105]; void Fill(int i, int j) { for (int k = 0 ; k < 2; ++k) { if (i + dx[k] < m && j + dy[k] < n && !a[i+dx[k]][j+dy[k]] && !d[i+dx[k]][j+dy[k]]) { d[i+dx[k]][j+dy[k]] = d[i][j] + 1; Fill (i + dx[k], j + dy[k]); } } } int main() { cin >> m >> n; for (int i = 0; i < m; ++i) { cin >> s; for (int j = 0; j < n; ++j) { if (s[j] == '&') a[i][j] = 1; } } if (!a[0][0]) { d[0][0] = 1; Fill (0, 0); } for (int i = 0; i < m; ++i) for (int j = 0; j < n; ++j) sol = max (sol, d[i][j]); cout << sol; return 0; }