#include <queue>
#include <bits/stdc++.h>
using namespace std;
char map[25][25];
int mov[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
int vis[25][25] = {0}, d[25][25];
int n, m;
struct node
{
	int x, y;
}now, tmp;
int solve(int x, int y)
{
	queue <struct node> q;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
		{
			vis[i][j] = 0; d[i][j] = 1e9;
		}
	d[x][y] = 0;
	vis[x][y] = 1;
	now.x = x; now.y = y;
	q.push(now);
	while(!q.empty())
	{
		now = q.front(); q.pop();
		for(int i = 0; i < 4; i++)
		{
			tmp.x = now.x + mov[i][0];
			tmp.y = now.y + mov[i][1];
			if(tmp.x<=0||tmp.x>n||tmp.y<=0||tmp.y>m) continue;
			if(map[tmp.x][tmp.y]=='#') continue;
			if(vis[tmp.x][tmp.y]) continue;
			d[tmp.x][tmp.y] = 1 + d[now.x][now.y];
			vis[tmp.x][tmp.y] = 1;
			q.push(tmp);
		}
	}
	int res = 0;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
		{
			if(vis[i][j] && res < d[i][j]) res = d[i][j];
		}
	return res;
}
int main()
{
	int res = 0;
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++)
		scanf("%s", map[i]+1);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
		if(map[i][j]=='.')
		{
			res = max(res, solve(i, j));
		}
	printf("%d\n", res);
}