/----------------------------------------------------------------------
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int h, w;
    cin >> h >> w;
    vector<vector<bool>> maize(h);
    REP(i,h) {
        string s;
        cin >> s;
        REP(j, s.size()) {
            if(s[j]=='#') {
                maize[i].push_back(false);
            }else{
                maize[i].push_back(true);
            }
        }
    }

    int ans = 0;
    REP(i,h)
    REP(j,w) {
        vector<vector<int>> dist(h);
        REP(nn,h) dist[nn].resize(w,-1);
        queue<P> que;
        
        auto push = [&] (int nx, int ny, int nd) {
            if(nx < 0 || ny < 0 || nx >= w || ny >= h) return;
            if(dist[ny][nx] != -1 || !(maize[ny][nx])) return;
            que.push(make_pair(nx,ny));
            dist[ny][nx] = nd;
        };

        push(j,i,0);
        while(!que.empty()) {
            P tmp = que.front(); que.pop();
            int newx = tmp.first;
            int newy = tmp.second;
            int tmpd = dist[newy][newx];

            push(newx+1, newy, tmpd+1);
            push(newx-1, newy, tmpd+1);
            push(newx, newy+1, tmpd+1);
            push(newx, newy-1, tmpd+1);
        }
        REP(i,h)
        REP(j,w) {
            ans = max(ans,dist[i][j]);
        }
    }
    cout  << ans << endl;
    return 0;
}