#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

ll h, w;
vector<string> s;
ll dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};

ll bfs(ll x, ll y) {
    queue<pair<ll, ll>> q;
    vector<vector<ll>> dist(h, vector(w, INF));
    q.emplace(x, y);
    dist[x][y] = 0;
    while(!q.empty()) {
        pair<ll, ll> p = q.front();
        q.pop();
        rep(i, 0, 4) {
            ll nx = p.first + dx[i], ny = p.second + dy[i];
            if(0 <= nx && nx < h && 0 <= ny && ny < w) {
                if(s[nx][ny] == '.' && dist[nx][ny] == INF) {
                    dist[nx][ny] = dist[p.first][p.second] + 1;
                    q.emplace(nx, ny);
                }
            }
        }
    }
    ll ans = 0;
    rep(i, 0, h) rep(j, 0, w) if(dist[i][j] != INF) chmax(ans, dist[i][j]);
    return ans;
}

int main() {
    cin >> h >> w;
    s.resize(h);
    rep(i, 0, h) cin >> s[i];
    ll ans = 0;
    rep(i, 0, h) rep(j, 0, w) if(s[i][j] == '.') chmax(ans, bfs(i, j));
    cout << ans << endl;
}
