#include <bits/stdc++.h>
#define MAXN int(10e5+3)
#define f first
#define s second
#define int long long
using namespace std;
typedef pair<int, pair<int, int> > piii;
typedef pair<int, int> pii;

char m[23][23];
int dist[23][23], processado[23][23];
int iv = 0, jv = 0, av = 0, l, c;

int x[] = {1, -1, 0, 0};
int y[] = {0, 0, 1, -1};

priority_queue<piii, vector<piii>, greater<piii> > fila;

void solve(int i, int j, int tam) {

    dist[i][j] = tam;
    for(int z = 0; z < 4; z++) {
        if(i+x[z] >= 0 && i+x[z] < l && j+y[z] >= 0 && j+y[z] < c && m[i+x[z]][j+y[z]] == '.') {
            pair<int, pii> xd;
            xd.first = tam+1;
            xd.second = pii(i+x[z], j+y[z]);
            fila.push(xd);
        }
    }

    while(!fila.empty()) {

        if(processado[fila.top().second.first][fila.top().second.second] == 1) {
            fila.pop();
            continue;
        }

        if(fila.top().first > av)
            av = fila.top().first;

        processado[fila.top().second.first][fila.top().second.second] = 1;
        solve(fila.top().second.first, fila.top().second.second, fila.top().first);
    }
    return;
}

int main() {
    cin >> l >> c;

    for(int i = 0; i < l; i++)
        for(int j = 0; j < c; j++)
            cin >> m[i][j];

    for(int i = 0; i < l; i++)
        for(int j = 0; j < c; j++) {
            if(m[i][j] == '.') solve(i, j, 0);
            memset(dist, 0, sizeof dist);
            memset(processado, 0, sizeof processado);
        }
    cout << av << endl;
}
