#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=24;
const int INF=0x3f3f3f3f;
int n,m;
char mp[N][N];
int dis[N*N][N*N];
int id[N][N],cur;
int main() {
	memset(dis,INF,sizeof(dis));
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;++i) {
		scanf("%s",mp[i]+1);
		for (int j=1;j<=m;++j) {
			id[i][j]=++cur;
			if (i>1) {
				if (mp[i-1][j]=='.'&&mp[i][j]=='.')
					dis[id[i-1][j]][id[i][j]]=dis[id[i][j]][id[i-1][j]]=1;
			}
			if (j>1) {
				if (mp[i][j-1]=='.'&&mp[i][j]=='.')
					dis[id[i][j-1]][id[i][j]]=dis[id[i][j]][id[i][j-1]]=1;
			}
		}
	}
	for (int i=1;i<=cur;++i) dis[i][i]=0;
	for (int k=1;k<=cur;++k)
		for (int i=1;i<=cur;++i)
			for (int j=1;j<=cur;++j)
				dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
	int ans=0;
	for (int i=1;i<=cur;++i)
		for (int j=1;j<=cur;++j)
			if (dis[i][j]^INF)
				ans=max(ans,dis[i][j]);
	printf("%d\n",ans);
	return 0;
}