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

int p,q;
vector<vector<char>> vec;
int ans=0;

void bfs(int h,int w){
  vector<vector<int>> dist(p,vector<int>(q,-1));
  dist.at(h).at(w)=0;
  vector<int> mx(4),my(4);
  mx={-1,0,1,0};
  my={0,1,0,-1};
  queue<pair<int,int>> Q;
  Q.push({h,w});
  while(Q.size()){
    int h=Q.front().first;
    int w=Q.front().second;
    Q.pop();
    for(int i=0;i<4;i++){
      int nh=h+mx.at(i);
      int nw=w+my.at(i);
      if(nh<0||nh>=p||nw<0||nw>=q) continue;
      if(vec.at(nh).at(nw)=='#') continue;
      if(dist.at(nh).at(nw)==-1){
        dist.at(nh).at(nw)=dist.at(h).at(w) + 1;
        Q.push({nh, nw});
        ans=max(ans,dist.at(nh).at(nw));
      }
    }
  }
}

int main(){
  cin>>p>>q;
  vec.resize(p,vector<char>(q));
  for(int i=0;i<p;i++){
    for(int j=0;j<q;j++){
      cin>>vec.at(i).at(j);
    }
  }
  for(int i=0;i<p;i++){
    for(int j=0;j<q;j++){
      if(vec.at(i).at(j)=='.'){
        bfs(i,j);
      }
    }
  }
  cout<<ans<<endl;
}