#include<bits/stdc++.h>
using namespace std;

int main(){
  int H,W;cin>>H>>W;
  vector<string>S(H);
  for(int i=0;i<H;i++)cin>>S[i];
  int ans=-1;
  for(int sy=0;sy<H;sy++)for(int sx=0;sx<W;sx++){
    if(S[sy][sx]=='#')continue;
    vector<vector<int>>D(H,vector<int>(W,-1));
    queue<pair<int,int>>q;
    q.push(pair<int,int>(sy,sx));
    D[sy][sx]=0;
    while(q.size()){
      pair<int,int>f=q.front();q.pop();
      int y=f.first,x=f.second;
      if(y-1>=0&&S[y-1][x]=='.'&&D[y-1][x]==-1){D[y-1][x]=D[y][x]+1;q.push(pair<int,int>(y-1,x));}
      if(y+1<H&&S[y+1][x]=='.'&&D[y+1][x]==-1){D[y+1][x]=D[y][x]+1;q.push(pair<int,int>(y+1,x));}
      if(x-1>=0&&S[y][x-1]=='.'&&D[y][x-1]==-1){D[y][x-1]=D[y][x]+1;q.push(pair<int,int>(y,x-1));}
      if(x+1<W&&S[y][x+1]=='.'&&D[y][x+1]==-1){D[y][x+1]=D[y][x]+1;q.push(pair<int,int>(y,x+1));}
    }
    for(int y=0;y<H;y++)for(int x=0;x<W;x++)ans=max(ans,D[y][x]);
  }
  cout<<ans;
}

