#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end() 

vector<ll> A{1,0,-1,0};
vector<ll> B{0,1,0,-1};


int main() {
ll H,W;
  cin>>H>>W;
vector<string> vec(H);
  for(ll i=0;i<H;i++) {
cin>>vec[i];
  }
  
  
  ll ans=0;
 for(ll i=0;i<H;i++) {
for(ll j=0;j<W;j++) {
  if(vec[i][j]=='#') {
continue;
  }
  vector<vector<ll>> dist(H,vector<ll>(W,-1));
  dist[i][j]=0;
  queue<pair<ll,ll>> S;
  S.push(make_pair(i,j));
  while(!S.empty()) {
    ll nh=S.front().first;
    ll nw=S.front().second;
    S.pop();
    for(ll h=0;h<4;h++) {
ll kh=nh+A[h];
      ll kw=nw+B[h];
      if(kh<0||kh>=H||kw<0||kw>=W) {
continue;
      }
      if(vec[kh][kw]=='#') {
continue;
      }
      if(dist[kh][kw]!=-1) {
continue;
      }
      
      dist[kh][kw]=dist[nh][nw]+1;
      S.push(make_pair(kh,kw));
    }
  }
  
  for(ll k=0;k<H;k++) {
for(ll g=0;g<W;g++) {
if(ans<dist[k][g]) {
ans=dist[k][g];
}
  }
  
}
 }
 }
  
  cout<<ans<<endl;
}
      
    

  

  
  
  
  
  
  
  
  
  

  
