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


def bfs(cur, mat):
	q = collections.deque([(cur,0)])
	vis =  set([])
	temp = 0
	while(q):
		u, dis = q.popleft()
		vis.add(u)
		i,j = u
		temp = max(temp, dis)
		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)
				q.append((nei, dis +1))
		

	return temp


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