import queue

h, w = map(int, input().split())

s = []
for i in range(h):
	tmp = input()
	s.append(tmp)

max = 0

def next(x, y, num):
	relist = []
	if x > 0 and s[x-1][y] == '.' and map[x-1][y] == '.':
		relist.append((x-1,y,num+1))
	if y > 0 and s[x][y-1] == '.' and map[x][y-1] == '.':
		relist.append((x,y-1,num+1))
	if x < h-1 and s[x+1][y] == '.' and map[x+1][y] == '.':
		relist.append((x+1,y,num+1))
	if y < w-1 and s[x][y+1] == '.' and map[x][y+1] == '.':
		relist.append((x,y+1,num+1))
	return relist

for i in range(h):
	for j in range(w):
		map = s.copy()
		q = queue.Queue()
		q.put((i, j, 0))
		map[i] = map[i][:j] + '#' + map[i][j+1:]
		while q.empty() == False:
			x, y, num = q.get()
			if num > max:
				max = num
				xy = (i, j)
			list = next(x, y, num)
			for nx, ny, nnum in list:
				q.put((nx,ny,nnum))
				map[nx] = map[nx][:ny] + '#' + map[nx][ny+1:]

print(max)