import collections
h,w = map(int, raw_input().split(' '))
mat = [raw_input() for _ in range(h)]


def dfs(cur, vis, mat):
	i,j = cur

	temp = 0
	for nei in [(i+1, j), (i-1,j), (i,j-1), (i,j+1)]:
		if 0 <= nei[0]< len(mat) and 0<=nei[1]< len(mat[nei[0]]) and nei not in vis and mat[nei[0]][nei[1]] == '.':
			vis.add(nei)
			temp = max(temp, 1 + dfs(nei, vis, mat))
			vis.remove(nei)
	return temp

m = 0
for i in range(len(mat)):
	for j in range(len(mat[0])):
		if mat[i][j] == '.':
			m = max(m, dfs((i,j), set([(i,j)]), mat))
print m