#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

ll power(ll x,ll y,ll p) 
{ 
    ll res = 1;      
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 
char a[25][25];
ll vis[25][25];
ll d[25][25],lev[25][25];
ll N,M,INF=1e10;
void clean()
{
	for(ll i=1;i<=N;i++)
	{
		for(ll j=1;j<=M;j++)
		{
			vis[i][j]=0,d[i][j]=0;
		}
	}
}

ll bfs(ll i,ll j)
{
	queue<pll>Q;
	Q.push(mp(i,j));
	vis[i][j]=1;

	while(!Q.empty())
	{
		pll P=Q.front();
		Q.pop();

		if(P.ff-1>=1 && !vis[P.ff-1][P.ss] && a[P.ff-1][P.ss]=='.')
		{
			d[P.ff-1][P.ss]=d[P.ff][P.ss]+1;
			Q.push(mp(P.ff-1,P.ss));
			vis[P.ff-1][P.ss]=1;
		}
		if(P.ff+1<=N && !vis[P.ff+1][P.ss] && a[P.ff+1][P.ss]=='.')
		{
			d[P.ff+1][P.ss]=d[P.ff][P.ss]+1;
			Q.push(mp(P.ff+1,P.ss));
			vis[P.ff+1][P.ss]=1;
		}
		if(P.ss-1>=1 && !vis[P.ff][P.ss-1] && a[P.ff][P.ss-1]=='.')
		{
			d[P.ff][P.ss-1]=d[P.ff][P.ss]+1;
			Q.push(mp(P.ff,P.ss-1));
			vis[P.ff][P.ss-1]=1;
		}
		if(P.ss+1<=M && !vis[P.ff][P.ss+1] && a[P.ff][P.ss+1]=='.')
		{
			d[P.ff][P.ss+1]=d[P.ff][P.ss]+1;
			Q.push(mp(P.ff,P.ss+1));
			vis[P.ff][P.ss+1]=1;
		}
	}
}

int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;

	cin >> n >> m;
	N=n,M=m;
	for(i=1;i<=n;i++)
	{
		string s;
		cin >> s;
		for(j=1;j<=m;j++)
			a[i][j]=s[j-1];
	}
	ll ans=0;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			for(k=1;k<=n;k++)
			{
				for(ll p=1;p<=m;p++)
				{
					clean();
					bfs(i,j);
					// cout<<i<<" "<<j<<" "<<k<<" "<<p<<endl;
					if(vis[k][p])
						ans=max(ans,d[k][p]);
				}
			}
		}
	}
	cout<<ans<<endl;
}