#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> V;
typedef vector<vector<int>> Graph;

int main() {
    int h,w;
    cin >>> h >> w;
    vector<vector<char>> mp(h,vector<char>(w));
    char s;
    rep(i,h){
        rep(j,w){
            cin >> s;
            mp[i][j] = s;
        }
    }
    int ans = 0;
    rep(i,h){
        rep(j,w){
            if(mp[i][j]=='#') continue;
            queue<pair<int,int>> que;
            vector<V> dist(h,V(w,-1));
            dist[i][j] = 0;
            que.push(make_pair(i,j));
            while(!que.empty()){
                int x = que.front().first, y = que.front().second;
                que.pop();
                if(x>0&&dist[x-1][y]==-1&&mp[x-1][y]=='.'){
                    dist[x-1][y] = dist[x][y] + 1;
                    que.push(make_pair(x-1,y));
                    ans = max(ans,dist[x-1][y]);
                }
                if(y>0&&dist[x][y-1]==-1&&mp[x][y-1]=='.'){
                    dist[x][y-1] = dist[x][y] + 1;
                    que.push(make_pair(x,y-1));
                    ans = max(ans,dist[x][y-1]);
                }
                if(x<h-1&&dist[x+1][y]==-1&&mp[x+1][y]=='.'){
                    dist[x+1][y] = dist[x][y] + 1;
                    que.push(make_pair(x+1,y));
                    ans = max(ans,dist[x+1][y]);
                }
                if(y<w-1&&dist[x][y+1]==-1&&mp[x][y+1]=='.'){
                    dist[x][y+1] = dist[x][y] + 1;
                    que.push(make_pair(x,y+1));
                    ans = max(ans,dist[x][y+1]);
                }
            }
        }
    }
    cout << ans << endl;
}