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

int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};

vector<vector<int> > t, r;
vector<string> vec;

int bfs(int x){
  map<int,int> d;
  d[x]=0;
  queue<int> q;
  q.push(x);
  while(!q.empty()){
    int t = q.front();
    q.pop();
    for(int i = 0; i < 4; ++i){
      int xp = dx[i] + (t / w);
      int yp = dy[i] + (t % w);
      if(xp >= 0 && yp >= 0 && xp < h && yp < w){
	if(vec[xp][yp] == '.'){
	  if(!d.count(xp * w + yp)){
	    d[xp * w + yp] = d[t] + 1;
	    q.push(xp * w + yp);
	  }
	}
      }
    }
  }
  int res = 0;
  for(auto x : d){
    res = max(res, x.second);
  }
  return res;
}
int main(){
  cin>>h>>w;
  string s;
  vec.resize(h);
  for(int i = 0; i < h; ++i){
    cin>>vec[i];
  }
  int res = 0;
  for(int x = 0; x < w * h; ++x)if(vec[x/w][x%w]!='#')res = max(res, bfs(x));
  cout<<res<<endl;
  return 0;
}
