#include <bits/stdc++.h>
 
#define ff first
#define ss second
#define mp make_pair
 
using namespace std;
 
typedef long long ll;

int cnt[25][25];
char mat[25][25];
int n,m;
int r[4] = {-1,0,1,0};
int c[4] = {0,1,0,-1};

int bfs(int a, int b) {
	memset(cnt, -1, sizeof cnt);

	queue<pair<int,int>> Q;
	Q.emplace(a,b);
	cnt[a][b] = 0;

	while(!Q.empty()) {
		auto v = Q.front(); Q.pop();

		for(int i = 0; i < 4; i++) {
			int x = v.ff + r[i];
			int y = v.ss + c[i];

			if(x < 0 or x >= n or y < 0 or y >= m or mat[x][y] == '#' or cnt[x][y] != -1) continue;
			cnt[x][y] = cnt[v.ff][v.ss]+1;
			Q.emplace(x,y);
		}
	}

	int ret = 0;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			ret = max(ret, cnt[i][j]);
	return ret;
}

int main(){

	scanf("%d%d", &n, &m);

	for(int i = 0; i < n; i++)
		scanf(" %s", mat[i]);

	int ans = 0;

	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			if(mat[i][j] != '#')
				ans = max(ans, bfs(i,j));

	printf("%d\n", ans);

	return 0;
}