import queue
import copy

vx = [0,1,0,-1];
vy = [1,0,-1,0];
q = queue.Queue()

hw = input().split(' ');
h = int(hw[0]);
w = int(hw[1]);
s = [ [0]*w for i in range(h)];
for i in range(h) :
	si = input();
	for j in range(w) :
		s[i][j] = si[j];

s_alt = copy.deepcopy(s);
ans = 0;
for sy in range(h) :
	for sx in range(w) :
		s = copy.deepcopy(s_alt);
		q_a = [0]*2;
		q_a[0] = sy;
		q_a[1] = sx;
		q.put(q_a);
		s[sy][sx] = 0;
		while not q.empty() :
			q_a = q.get();
			for i in range(4):
				ny = q_a[0] + vy[i];
				nx = q_a[1] + vx[i];
				if ny >= 0 and ny < h and nx >= 0 and nx < w and s[ny][nx] == '.':
					s[ny][nx] = s[q_a[0]][q_a[1]] + 1;
					q_b = [0]*2;
					q_b[0] = ny;
					q_b[1] = nx;
					q.put(q_b);
		max_path = 0;
		for i in range(h) :
			for j in range(w) :
				if s[i][j] == '#' :
					continue;
				elif s[i][j] > max_path :
					max_path = s[i][j];
		if max_path > ans :
			ans = max_path;

print(ans);