#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 
 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert
#define ld long double
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
 
typedef long long int ll;
 
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn =100001;
ll power(ll x, ll n) {
    ll res = 1;
    for (; n > 0; n >>= 1) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    }
    return res;
}
string s[50];
ll h,w;
bool isvalid(ll i,ll j)
{
  return (s[i][j]=='.'&&i<h&&i>=0&&j<w&&j>=0);
}
vl g[400];
# define INF 1e18
  
// iPair ==>  Integer Pair 
typedef pair<ll, ll> iPair; 
vl djikstra(ll src) 
{   
  bool vis[h*w]={0};
    vl dist(h*w,INF);
    queue<ll> q;
    dist[src]=0;
    q.push(src);
    while(!q.empty())
    {
      ll u=q.front();
      //trace(u);
      q.pop();
      for(auto v:g[u])
      {
        if(!vis[v])
        { 
          vis[v]=1;
          dist[v]=dist[u]+1;
          q.push(v);
        }
      }
    }
    //cout<<dist<<endl;
    return dist;
}
int main()
{
  
  IOS
  cin>>h>>w;
  for(ll i=0;i<h;i++)
  {
    cin>>s[i];
  }
  for(ll i=0;i<h;i++)
  {
    for(ll j=0;j<w;j++)
    {
      for(ll ii=i-1;ii<=i+1;ii++)
      {
        for(ll jj=j-1;jj<=j+1;jj++)
        {
          if(abs(i-ii)+abs(j-jj)==1)
          {
            if(isvalid(i,j)&&isvalid(ii,jj))
            {
              g[i*w+j].pb(ii*w+jj);
            }
          }
        }
      }
      //cout<<g[i*w+j]<<endl;
    }
  }
  
  ll ans=1;
  for(ll i=0;i<h;i++)
  {
    for(ll j=0;j<w;j++)
    {
      if(isvalid(i,j))
       {  
          vl d= djikstra(i*w+j);
          //cout<<d<<endl;
      for(auto x:d)
      {
        if(!(x>1e15))
        {
          ans=max(ans,x);
        }
      }}
    }
  }
  cout<<ans<<endl;
  
  
  
}