#include <iostream>
#include <queue>
using namespace std;

typedef pair<int, int> cuplu;
char m[105][105];
int best[105][105];
queue<cuplu> Q;
int N, M, sol = 0;

void Read() {
    cin >> N >> M;
    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= M; ++j) {
            cin >> m[i][j];
            //cerr << m[i][j];
        }
        //cerr << '\n';
    }
}

void Solve() {
    do {
        cuplu node = Q.front();
        Q.pop();
        if (m[node.first][node.second + 1] == '.') {//accessible
            if (best[node.first][node.second + 1] < best[node.first][node.second] + 1) {
                best[node.first][node.second + 1] = best[node.first][node.second] + 1;
                Q.push(make_pair(node.first, node.second + 1));
            }
        }
        if (m[node.first + 1][node.second] == '.') {//accessible
            if (best[node.first + 1][node.second] < best[node.first][node.second] + 1) {
                best[node.first + 1][node.second] = best[node.first][node.second] + 1;
                Q.push(make_pair(node.first + 1, node.second));
            }
        }
    }while (!Q.empty());
}

void Write() {
    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= M; ++j) {
            sol = max(sol, best[i][j]);
        }
    }
    cout << sol + 1 << '\n';
}

int main() {
    Read();
    Q.push(make_pair(1, 1));
    Solve();
    Write();
    return 0;
}