#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;
 
int H,W;
int A[22][22];
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
 
int solve(int r,int c){
  int d[H][W],ret=0;
  rep(i,H) rep(j,W) d[i][j]=-1;
  d[r][c]=0;
  queue<pair<int,int>> que;
  que.push({r,c});
  while(que.size()){
    pair<int,int> p=que.front();
    que.pop();
    int i=p.first, j=p.second;
    rep(k,4){
      int ii=i+dx[k],jj=j+dy[k];
      if(ii<0||ii>=H) continue;
      if(jj<0||jj>=W) continue;
      if(A[ii][jj]==0) continue;
      if(d[ii][jj]==-1){
        d[ii][jj]=d[i][j]+1;
        que.push({ii,jj});
        ret=max(ret,d[ii][jj]);
      }
    }
  }
  return ret;
}
 
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  cin>>H>>W;
  rep(i,H){
    string S; cin>>S;
    rep(j,W) A[i][j]=(S[j]=='.');
  }
  int ans=0;
  rep(i,H) rep(j,W) if(A[i][j]) ans=max(ans,solve(i,j));
  cout<<ans<<endl;
  return 0;
}