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

int INF=INT_MAX;
char maze[25][25];
int di[]={0,1,0,-1};
int dj[]={1,0,-1,0};

int main(){
  int h,w; cin>>h>>w;
  rep(i,h)rep(j,w){
    cin>>maze[i][j];
  }
  int ans=0;
  rep(i,h)rep(j,w){
    if(maze[i][j]=='#') continue;
    vector<vector<int>> dis(h,vector<int>(w,INF));
    queue<P> q;
    q.push(make_pair(i,j));
    dis[i][j]=0;
    while(!q.empty()){
      int pi=q.front().first, pj=q.front().second;
      q.pop();
      rep(k,4){
        int ni=pi+di[k], nj=pj+dj[k];
        if(ni<0 || ni>=h || nj<0 || nj>=w) continue;
        if(maze[ni][nj]=='#') continue;
        if(dis[ni][nj]!=INF) continue;
        dis[ni][nj]=dis[pi][pj]+1;
        q.push(make_pair(ni,nj));
      }
    }
    rep(hi,h)rep(wi,w){
      if(dis[hi][wi]!=INF) ans=max(ans,dis[hi][wi]);
    }
  }
  cout<<ans<<endl;
}

