from collections import Counter, deque, defaultdict
from functools import lru_cache

h,w=map(lambda x:int(x),input().split())
g=[[0 for j in range(w)] for i in range(h)]
s=set()
for i in range(h):
	x = input()
	for j in range(len(x)):
		if x[j] == '#':
			s.add((i,j))
		g[i][j] = x[j]

tmax=0
for i in range(h):
	for j in range(w):
		if (i,j) in s:
			continue
		vis=set()
		d=deque()
		d.append((i,j,0))
		while d:
			i,j,x=d.popleft()
			for di,dj in [(-1, 0), (1,0), (0,1), (0,-1)]:
				if (i+di,j+dj) in s:
					continue
				if i+di >=h or i+di <0 or j+dj >=w or j+dj <0:
					continue
				if (i+di,j+dj) in vis:
					continue
				vis.add((i+di,j+dj))
				d.append((i+di,j+dj, x+1))
				tmax=max(tmax, x+1)
print(tmax)
			