#include<bits.stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
ll INF = 1000000;
int main(){
    ll h, w, ans=0,tmp,start,goal;
    cin >> h >> w;
    vector<vector<char> > vec(h+2, vector<char>(w+2,'#'));
    ll dp[h+2][w+2][h+2][w+2];
    rep(i,h+2)rep(j,w+2)rep(k,h+2)rep(l,w+2)dp[i][j][k][l]=INF;
    rep(i,h)rep(j,w){
        cin >> vec.at(i+1).at(j+1);
    }
    int mvx[4]={0,-1,0,1},mvy[4]={-1,0,1,0};
    rep(i,h)rep(j,w){
        if(vec.at(i+1).at(j+1)=='.'){
            rep(k,4){
                if(vec.at(i+1+mvx[k]).at(j+1+mvy[k])=='.'){
                    dp[i+1][j+1][i+1+mvx[k]][j+1+mvy[k]]=1;
                }
            }
        }
    }
    rep(m,h){
        rep(n,w){
            rep(i,h){
                rep(j,w){
                    rep(k,h){
                        rep(l,w){
                            dp[i+1][j+1][k+1][l+1]=min(dp[i+1][j+1][k+1][l+1],dp[i+1][j+1][m+1][n+1]+dp[m+1][n+1][k+1][l+1]);
                        }
                    }
                }
            }
        }
    }
    ll mx=0LL;
    rep(i,h)rep(j,w)rep(k,h)rep(l,w){
        mx=max(mx,(dp[i+1][j+1][k+1][l+1]<INF)?dp[i+1][j+1][k+1][l+1]:0);
    }
    cout << mx << endl;
}
