#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x " = " << (x) << '\n';
#define P(x) cout << #x << '\n';    
#define int long long
typedef pair<int, int> pii;
const int mod = 1000000007;

const int maxn = 30;
int a[maxn][maxn];
int h, w;
int vis[maxn][maxn];
struct node
{
	int x, y, mov = 0; 
};
queue<node> q;
bool isv(int i, int j, int mov)
{
	if(i >= 1 && i <= h && j >= 1 && j <= w && a[i][j] == 1 && vis[i][j] == 0)
	{
		vis[i][j] = 1;
		q.push({i, j, mov + 1});
	}
}

int bfs(int stx, int sty, int destx, int desty)
{
	while(!q.empty()) q.pop();
	for(int i = 1; i <= h; ++ i)
		for(int j = 1; j <= w; ++ j)
			vis[i][j] = 0;
	q.push({stx, sty, 0LL});
	vis[stx][sty] = 1;
	int ans = 0;
	while(!q.empty())
	{
		node cur = q.front();
		q.pop();
		int x = cur.x, y = cur.y, mov = cur.mov;
		if(x == destx && y == desty)
		{
			ans = mov;
			break;
		}
		isv(x + 1, y, mov);
		isv(x - 1, y, mov);
		isv(x , y + 1, mov);
		isv(x, y - 1, mov);
		
	}
	return ans;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(9);
	#ifdef LOCAL_DEFINE
		freopen("in.txt", "rt", stdin);
	#endif
	
	cin >> h >> w;
	for(int i = 1; i <= h; ++ i)
	{
		for(int j = 1; j <= w; ++ j)
		{
			char ch;
			cin >> ch;
			if(ch == '.')
			{
				a[i][j] = 1;
			}
			else
			{
				a[i][j] = -1;
			}
		}
	}
	int ans = 0;
	for(int i = 1; i <= h; ++ i)
	{
		for(int j = 1; j <= w; ++ j)
		{
			for(int x = 1; x <= h; ++ x)
			{
				for(int y = 1; y <= w; ++ y)
				{
					ans = max(ans, bfs(i, j , x, y));
				}
			}
		}
	}
	cout << ans << '\n';
	
	return 0;
}




