#頂点の数をN、変の数をMとするとO(N+M)
#queueは遅いからdequeを使う
from collections import deque
from copy import deepcopy

q = deque()
h,w = map(int,input().split())
c = [['#' for _ in range(w+2)]]
for _ in range(h):
	c.append(list('#'+input()+'#'))
c.append(['#' for _ in range(w+2)])

ans = [[0 for _ in range(w+2)]for _ in range(h+2)]
c_copy = deepcopy(c)
ans_copy = deepcopy(ans)
def bfs(x,y):
	global q
	global c
	q.append([x,y])
	num = 0

	while q:
		x,y = q.popleft()
		if c[y][x-1] == '.':
			q.append([x-1,y])
			ans[y][x-1] = ans[y][x] + 1
			num = ans[y][x-1]
			c[y][x-1] = '#'
		if c[y][x+1] == '.':
			q.append([x+1,y])
			ans[y][x+1] = ans[y][x] + 1
			num = ans[y][x+1]
			c[y][x+1] = '#'
		if c[y-1][x] == '.':
			q.append([x,y-1])
			ans[y-1][x] = ans[y][x] + 1
			num = ans[y-1][x]
			c[y-1][x] = '#'
		if c[y+1][x] == '.':
			q.append([x,y+1])
			ans[y+1][x] = ans[y][x] + 1
			num = ans[y+1][x]
			c[y+1][x] = '#'
	return num

tmp = 0
for i in range(1,h+1):
	for j in range(1,w+1):
		c = deepcopy(c_copy)
		ans = deepcopy(ans_copy)
		if c[i][j] == '.':
			tmp = max(tmp,bfs(j,i))
print(tmp)
