#include #include #include #include #include #include #include #include #include #include #include #define pb push_back #define mp make_pair #define f first #define s second #define ll long long using namespace std; const int MAXN = 105; char mat[MAXN][MAXN]; int ret[MAXN][MAXN]; int N, M; int calc(int x, int y) { if (x < 1 || x > N) { return 0; } if (y < 1 || y > M) { return 0; } if (ret[x][y] != -1) { return ret[x][y]; } if (mat[x][y] == '&') { return (ret[x][y] = 0); } return (ret[x][y] = max( calc(x+1, y), calc(x, y+1) ) + 1); } int main() { /* freopen("test.in","r", stdin); freopen("test.out", "w", stdout); */ scanf("%d %d\n", &N, &M); for (int i = 0; i <= N; ++i) { for (int j = 0; j <= M; ++j) { ret[i][j] = -1; } } for (int i = 1; i <= N; ++i) { scanf("%s\n", mat[i] + 1); } //D[i][j] = max(D[i - 1][j] + 1, D[i][j - 1] + 1) cout << calc(1, 1); return 0; }