#include<bits/stdc++.h>
using namespace std
  int ans; int h,w;
int grid[21][21];
const int dx[] = {-1, 0, 1, 0, -1,-1, 1, 1};
const int dy[] = { 0, 1, 0,-1, -1, 1,-1, 1};
bool isallowed(int x,int y)
{
  if(x>=0 and x<h and y>=0 and y<w and grid[x][y])
    return true;
  return false;
}
void bfs(int r,int c)
{
  int vis[h][w];
  memset(vis,0,sizeof(vis));
  queue<pair<int,pair<int,int>>>q;
  q.push({r,{c,0}});
  while(!q.empty())
  {
    r=q.front().first;
    c=q.front().second.first;
    int d=q.front().second.second;
    q.pop();
    vis[r][c]=1;
    ans=max(ans,d);
    for(int i=0;i<4;i++)
    {
      if(isallowed(r+dx[i],c+dy[i]) and !vis[r+dx[i]][c+dy[i]])
        q.push({r+dx[i],{c+dy[i],d+1}});
    }
  }
}
  int main()
{
 
  cin>>h>>w;
  string s;
  
  for(int i=0;i<h;i++)
  {
    cin>>s;
    for(int j=0;j<w;j++)
    {
      if(s[j]=='.')
        grid[i][j]=1;
      else
        grid[i][j]=0;
    }
  }
  for(int i=0;i<h;i++)
  {
    for(int j=0;j<w;j++)
    {
      if(grid[i][j])
        bfs(i,j);
    }
  }
    cout<<ans<<"\n";
    return 0;
  }
