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

const int maxn = 21;
const int dx[] = {0,0,1,-1};
const int dy[] = {1,-1,0,0};

int n, m, f[maxn][maxn], cur;
char a[maxn][maxn];

void dfs(int x, int y)
{
	queue<pair<int,int> > Q;
	Q.push(make_pair(x,y));
	while(!Q.empty())
	{
	x = Q.front().first;
	y = Q.front().second;
	Q.pop();
	cur = max(cur, f[x][y]);
	
	for(int k = 0; k <= 3; ++ k)
	{
		int nx = x + dx[k], ny = y + dy[k];
		if(nx < 1 || ny < 1 || nx > n || ny > m) continue;
		if(a[nx][ny] == '#') continue;
		if(f[nx][ny] != -1) continue;
		f[nx][ny] = f[x][y] + 1;
		Q.push(make_pair(nx,ny));
	}
	}
}

int main()
{
	#ifdef MPS
		freopen("a.in","r",stdin);
		freopen("a.out","w",stdout);
	#endif
	scanf("%d%d",&n,&m);
	int ans = 0;
	for(int i = 1; i <= n; ++ i) scanf("%s",a[i]+1);
	for(int sx = 1; sx <= n; sx ++)
		for(int sy = 1; sy <= m; sy ++) if(a[sx][sy] != '#')
		{ 
			memset(f,-1,sizeof(f));
			cur = 0;
			f[sx][sy] = 0;
			dfs(sx, sy);
			ans = max(ans, cur);
		}
	printf("%d\n",ans);
	return 0;
}