#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;
int h,w;
const int dx[]={1,0,-1,0};
const int dy[]={0,-1,0,1};
bool judge(int i,int j)
{
  if(i<0||i>=h||j<0||j>=w) return false;
  else return true;
}

int main()
{
  cin>>h>>w;
  vector<string> s(h);
  for(auto&& e: s) 
  {
    cin>>e;
  }
  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>> num_field(h,vector<int>(w,-1));
      num_field[i][j]=0;
      queue<pair<int,int>> next_point;
      next_point.push(make_pair(i,j));
      while(!next_point.empty())
      {
        int x=next_point.front().first;
        int y=next_point.front().second;
        next_point.pop();
        for (int k = 0; k < 4; ++k)
        {
          int nx=x+dx[k],ny=y+dy[k];
          if(judge(nx,ny,h,w)&&num_field[nx][ny]==-1&&s[nx][ny]=='.')
          {
            next_point.push(make_pair(nx,ny));
            num_field[nx][ny]=1+num_field[x][y];
          }
        }
      }
      for (int x = 0; x < h; ++x)
      {
        for (int y = 0; y < w; ++y)
        {
          ans=(num_field[x][y]>ans)?num_field[x][y]:ans;
        }
      }
    }
  }
  cout<<ans;
}