#include <bits/stdc++.h>

using namespace std;

#define long long long
#define INF ((long) 2e18)
#define MOD ((long) (1e9 + 7))
#define umap unordered_map

long dist[30][30];

long solve(auto &a, long i, long j, long h, long w)
{
    queue<pair<long, long>> q;
    q.push({i, j});
    long worst = -INF;
    dist[i][j] = 0;
    while (not q.empty()) {
        auto p = q.front();
        i = p.first;
        j = p.second;
        q.pop();
        vector<pair<long, long>> next = {
            {i, j-1}, {i, j+1}, {i-1, j}, {i+1, j}
        };
        for (auto &x : next) {
            long l = x.first;
            long r = x.second;
            if (l < 0 or l >= h or r < 0 or r >= w) continue;
            if (a[l][r] != '.') continue;
            a[l][r] = '*';
            dist[l][r] = dist[i][j] + 1;
            worst = max(worst, dist[l][r]);
            q.push({l, r});
        }
    }
    return worst;
}

int main()
{
    ios::sync_with_stdio(true); cin.tie(0); cout.tie(0);

    long t = 1;
    //cin >> t;

    while (t--) {
        long h, w;
        cin >> h >> w;

        vector<string> a(h);
        for (auto &x : a) cin >> x;

        long best = -1;
        for (long i = 0; i < h; i++) {
            for (long j = 0; j < w; j++) {
                if (a[i][j] == '#') continue;
                long x = solve(a, i, j, h, w);
                best = max(best, x);
                for (long i = 0; i < h; i++) {
                    for (long j = 0; j < w; j++) {
                        if (a[i][j] == '*') {
                            a[i][j] = '.';
                        }
                    }
                }
            }
        }
        printf("%lld\n", best);
    }
}
