# coding: utf-8

def main():
	H, W = (int(x) for x in input().split())
	S = [[] for x in range(H)]

	for i in range(H):
		S[i] = [x for x in input()]

	# 隣接行列の作成
	inf = 1000000

	nodes = []
	for i in range(H):
		for j in range(W):
			if S[i][j] == ".":
				nodes.append([i, j])
	
	g = [[inf for j in range(len(nodes))] for i in range(len(nodes))]
	for i in range(len(nodes)):
		for j in range(len(nodes)):
			if   nodes[i][0] == nodes[j][0] and nodes[i][1] == nodes[j][1]:
				g[i][j] = 0
			elif abs(nodes[i][0]-nodes[j][0]) + abs(nodes[i][1]-nodes[j][1]) == 1:
				g[i][j] = 1

	max = 0
	for k in range(len(g[0])):
		for i in range(len(g[0])):
			for j in range(len(g[0])):
				g[i][j] = min(g[i][j], g[i][k] + g[k][j])

	for i in range(len(g[0])):
		for j in range(len(g[0])):
			if max < g[i][j]:
				max = g[i][j]
                
	print(max)

if __name__ == "__main__":
	main()