#include <bits/stdc++.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll Nmax=1e9;
const ll INF=1e9;
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  int h,w;
  cin>>w>>h;
  vector<string> s(h);
  rep(i,w){
    cin>>s[i];
  }
  int ans=0;
  
  map<P,int> dist0;
  rep(i,w){
    rep(j,h){
      dist0[make_pair(i,j)]=-1;
    }
  }
  
  

  rep(i,w){
    rep(j,h){//出発マス..(i,j)
      map dist=dist0;

      if(s[i][j]=='#'){
        continue;
      }

      queue<P> q;
      q.push(make_pair(i,j));
      dist[make_pair(i,j)]=0;

      while(!q.empty()){
        auto p=q.front();
        q.pop();
        int i0=p.first;
        int j0=p.second;
        rep(k,4){
          int i1=i0+dx[k];
          int j1=j0+dy[k];
          P q0=make_pair(i0,j0);
          P q1=make_pair(i1,j1);
          if(i1<0 || j1<0 || i1>=w || j1>= h){
            continue;
          }
          if(s[i1][j1]=='#'){
            continue;
          }
          if(dist[q1]>=0){
            continue;
          }
          dist[q1]=dist[q0]+1;
          q.push(q1);
          ans=max(ans,dist[q1]);
        }
      }



    }
  }
  cout<<ans<<endl;

}
