#include<bits/stdc++.h>
using namespace std;

const int maxn=25;
int dx[5]={0,0,0,1,-1},dy[5]={0,1,-1,0,0};
int h,w,a[maxn][maxn],ans;
int cnt[maxn][maxn];
queue<int> q;

void bfs(int x,int y)
{
	memset(cnt,0,sizeof cnt);
	q.push((x-1)*w+y);
	cnt[x][y]=1;
	while(!q.empty()) {
		int now=q.front();q.pop();
		int nx=(now+w-1)/w,ny=now-(nx-1)*w;
		for(int i=1;i<=4;++i) {
			if(nx+dx[i]>0&&nx+dx[i]<=h&&ny+dy[i]>0&&ny+dy[i]<=w&&
			a[nx+dx[i]][ny+dy[i]]&&!cnt[nx+dx[i]][ny+dy[i]]) {
				cnt[nx+dx[i]][ny+dy[i]]=cnt[nx][ny]+1;
				q.push((nx+dx[i]-1)*w+ny+dy[i]);
			}
		}
	}
	for(int i=1;i<=h;++i)
		for(int j=1;j<=w;++j) ans=max(ans,cnt[i][j]-cnt[x][y]);
}

int main()
{
	scanf("%d %d",&h,&w);
	for(int i=1;i<=h;++i)
		for(int j=1;j<=w;++j) {
			char s=getchar();
			while(s!='#'&&s!='.') s=getchar();
			if(s=='.') a[i][j]=1;
		}
	for(int i=1;i<=h;++i)
		for(int j=1;j<=w;++j) {
			if(a[i][j]) bfs(i,j);
		}
	printf("%d",ans);
}