#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
const int INF=1001001001;

int main() {
  int H,W;
  cin>>H>>W;
  vector<string>S(H);
  for(int i=0;i<H;i++){
    cin>>S[i];
  }
  
  vector<int>dx={0,0,1,-1};
  vector<int>dy={1,-1,0,0};
  queue<pair<int,int>>q;
  int ans=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(S[i][j]=='#'){continue;}
      vector<vector<int>>cost(H,vector<int>(W,-1));
      cost[i][j]=0;
      q.push(make_pair(i,j)); 
      while(!q.empty()){
        auto p=q.front();q.pop();
        int y=p.first,x=p.second;
        
        for(int d=0;d<4;d++){
          if(y+dy[d]>=H||x+dx[d]>=W||y+dy[d]<0||x+dx[d]<0){continue;}
          if(cost[y+dy[d]][x+dx[d]]!=-1){continue;}
          if(S[y+dy[d]][x+dx[d]]=='#'){continue;}
          cost[y+dy[d]][x+dx[d]]=cost[y][x]+1;
          q.push(make_pair(y+dy[d],x+dx[d]));  
        }
        ans=max(ans,cost[y][x]);
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}