from collections import deque
import copy

H, W = map(int, input().split())
lst = []
for _ in range(H):
	S = list(map(str, input()))
	lst.append(S)
	
ans = 0


# 入力: 座標、かかってる時間
# 出力: 最深部に到達するまでにかかる時間
def bfs(sh, sw):
	distance = [[400 for _ in range(W)] for _ in range(H)]
	for i in range(H):
		for j in range(W):
			if lst[i][j] == "#":
				distance[i][j] = -1
	distance[sh][sw] = 0
	Q = deque([[sh, sw, 0]])
	while Q:
		ch, cw, time = Q.popleft()
		if distance[ch][cw] < time: # すでにもっと早い道が存在
			continue
		for move_h, move_w in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
			new_h, new_w = ch + move_h, cw + move_w 
			if 0 <= new_h and new_h <= H - 1 and 0 <= new_w and new_w <= W - 1:
				if lst[new_h][new_w] == "#": continue
				Q.append([new_h, new_w, time + 1])
				distance[new_h][new_w] = min(distance[new_h][new_w], time + 1)
	res = 0
	for i in range(H):
		res = max(res, max(distance[i]))
	
	return res
	
# スタート位置全通り
for sh in range(H):
	for sw in range(W):
		if lst[sh][sw] == "#": continue # 壁の時はスキップ
		ans = max(ans, bfs(sh, sw))
		
print(ans)
