/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(unsigned int a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef unsigned int ll;
typedef long double ld;
typedef pair<unsigned int,unsigned int> pii;
typedef pair<unsigned int,unsigned int> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e9;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    
//-----------------------------------------------------------------------------------------------------------//

    READV(H);
    READV(W);
    char A[H][W];
    map<pll,ll> Ind;
    ll prev=0;
    FORI(i,0,H)
    {
        FORI(j,0,W)
        {
            READ(A[i][j]);
            Ind[{i,j}]=prev;
            prev++;
        }
    }
    vector<ll> ADJ[H*W];
    FORI(i,0,H)
    {
        FORI(j,0,W)
        {
            if (A[i][j]=='.')
            {
                if (i+1<H && A[i+1][j]=='.')
                {
                    ADJ[Ind[{i+1,j}]].pb({Ind[{i,j}]});
                    ADJ[Ind[{i,j}]].pb({Ind[{i+1,j}]});
                }
                if (j+1<W && A[i][j+1]=='.')
                {
                    ADJ[Ind[{i,j+1}]].pb({Ind[{i,j}]});
                    ADJ[Ind[{i,j}]].pb({Ind[{i,j+1}]});
                }
            }
        }
    }
    ll dp[H*W][H*W];
    FORI(i,0,H*W)
    {
        FORI(j,0,H*W)
        {
            dp[i][j]=inf;
        }
    }
    FORI(i,0,H*W)
    {
        dp[i][i]=0;
        for(auto v:ADJ[i])
        {
            dp[i][v]=1;
            dp[v][i]=1;
        }
    }
    FORI(i,0,H*W)
    {
        FORI(j,0,H*W)
        {
            FORI(k,0,H*W)
            {
                if (dp[i][k] < inf && dp[k][j] < inf)
                {dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
                dp[j][i]=dp[i][j];}
            }
        }
    }
    ll ans=0;
    FORI(i,0,H*W)
    {
        FORI(j,0,H*W)
        {
            if(dp[i][j]!=inf)
            {ans=max(ans,dp[i][j]);}
        }
    }
    cout<<ans<<endl;

//-----------------------------------------------------------------------------------------------------------//



    return 0;
}