#include <cstdio>
#include <iostream>
#include <fstream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <ctype.h>
#include <cstring>
#include <string>
#include <ctime>
#include <cassert>
#include <utility>

using namespace std;

int n, m, smax;
char mat[105][105];

class point {
    public:
        int y, x, scor; // y = line, x = column
        point(int x, int y, int scor) {
            this->x = x;
            this->y = y;
            this->scor = scor;
        }
        point() {
            x = 0;
            y = 0;
            scor = 1;
        }
};

void dfs(point p) {
    vector<point> vp;
    if(p.x + 1 < m && mat[p.y][p.x + 1] != '&')
        vp.push_back(point(p.x + 1, p.y, p.scor + 1));
    if(p.y + 1 < n && mat[p.y + 1][p.x] != '&')
        vp.push_back(point(p.x, p.y + 1, p.scor + 1));
    for(int i = 0; (unsigned) i < vp.size(); i++) {
        point aux = vp[i];
        dfs(aux);
        smax = max(smax, aux.scor);
    }
}

int main() {
//	freopen("date.in", "r", stdin);
//	freopen("date.out","w", stdout);

    cin >> n >> m;

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            cin >> mat[i][j];
        }
    }

    point p = point();
    smax = 1;

    dfs(p);

	cout << smax;
	return 0;
}