#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

bool vis[25][25];
string arr[25];

vector<pair<ll,ll>> moves = {{-1,0},{1,0},{0,-1},{0,1}};

int main()
{
   FAST/**/
   
   ll h,w;
   cin>>h>>w;
   
   rep(h)
        cin>>arr[i];
   
   ll ans = 0;
   
   for(ll i=0;i<h;i++)
   {
       for(ll j=0;j<w;j++)
       {
           if(arr[i][j] == '#')
                continue;
           memset(vis,0,sizeof(vis));
           queue<pair<ll,ll>> q;
           q.push(mp(i,j));
           vis[i][j] = 1;
           
           ll dis[h][w];
           repi(i1,j)
                repi(j1,w)
                    dis[i1][j1] = inf;
           
           dis[i][j] = 0;
           
           while(q.size()>0)
           {
               auto curr = q.front();
               q.pop();
               
               repi(i1,4)
               {
                   pair<ll,ll> p;
                   p.ff = curr.ff + moves[i1].ff;
                   p.ss = curr.ss + moves[i1].ss;
                   
                   if(p.ff<0 || p.ff>=h || p.ss<0 || p.ss>=w)
                        continue;
                   if(vis[p.ff][p.ss]) 
                        continue;
                   if(arr[p.ff][p.ss] == '#')
                        continue;
                   vis[p.ff][p.ss] = 1;
                   dis[p.ff][p.ss] = dis[curr.ff][curr.ss] + 1;
                   ans = max(ans, dis[p.ff][p.ss]);
                   q.push(p);
               }
           }
       }
   }
   
   cout<<ans;
           
   
   return 0;        
}  
   