ｖ#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int H, W;
vector<string> Graph(21);

int solve(int i, int j, int k, int l) {
    if (Graph[i][j] == '#' || Graph[k][l] == '#') return 0;

    vector<vector<int>> dist(H, vector<int>(W, -1));  // -1: 未訪問
    queue<P> que;

    que.push(make_pair(i, j));  // スタート地点をプッシュ
    dist[i][j] = 0;

    while (!que.empty()) {
        P p = que.front();
        que.pop();
        for (int direction = 0; direction < 4; ++direction) {
            int nh = p.first + dx[direction];
            int nw = p.second + dy[direction];
            if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
            if (dist[nh][nw] > -1) continue;
            if (Graph[nh][nw] == '#') continue;
            dist[nh][nw] = dist[p.first][p.second] + 1;
            if (nh == k && nw == l) {
                //ゴール
                return dist[k][l];
            }
            que.push(make_pair(nh, nw));
        }
    }
    return 0;
}

int main() {
    cin >> H >> W;
    rep(i, H) cin >> Graph.at(i);

    int ans = 0;
    rep(i, H) rep(j, W) rep(k, H) rep(l, W) {
        ans = max(ans, solve(i, j, k, l));
    }

    cout << ans << endl;
}
