import copy

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

def BFS(q):
	flg = copy.deepcopy(S)
	while q != []:
		cx,cy,cd = q.pop(0)
		if flg[cx][cy] == "#":
			continue
		else:
			flg[cx][cy] = "#"
		nps = [[cx+1,cy],[cx-1,cy],[cx,cy+1],[cx,cy-1]]
		for nx,ny in nps:
			if 0 <= nx < H and 0 <= ny < W:
				if flg[nx][ny] != "#":
					q.append([nx,ny,cd+1])

	return cd

ans = 0

for sx in range(H):
	for sy in range(W):
		if S[sx][sy] == "#":
			continue
		else:
			ans = max(ans,BFS([[sx,sy,0]]))

print(ans)