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

#define ran 22

const int go[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};

int n, m;
char s[ran][ran];
int q[ran*ran*2], l, r;
bool visd[ran][ran];
int dist[ran][ran];

void pb(int x, int y, int d) {
	q[r++] = x; q[r++] = y;
	visd[x][y] = true;
	dist[x][y] = d;
}

int bfs(int st_x, int st_y) {
	l = r = 0;
	memset(dist, -1, sizeof dist);
	memset(visd, false, sizeof visd);
	pb(st_x, st_y, 0);
	
	int res = 0;
	while(l<r) {
		int x = q[l++], y = q[l++];
		int d = dist[x][y];
		for(int i=0;i<4;i++) {
			int _x = x+go[i][0], _y = y+go[i][1];
			if(_x<0 || _x>=n || _y<0 || _y>=m || s[_x][_y]!='.' || visd[_x][_y])
				continue;
			pb(_x, _y, d+1);
			res = max(res, d+1);
		}
	}
	return res;
}

int main() {
	scanf("%d%d", &n, &m);
	for(int i=0;i<n;i++) scanf("%s", s[i]);
	
	int ans = 0;
	for(int i=0;i<n;i++)
	for(int j=0;j<m;j++)
		if(s[i][j]=='.') ans = max(ans, bfs(i, j));
	printf("%d\n", ans);
	
	return 0;
}