h,w=map(int,input().split())
s=[input()for _ in range(h)]

ans=0
dx = [1,0,-1,0]
dy = [0,1,0,-1] 
import queue
for si in range(h):
	for sj in range(w):
		if s[si][sj] == "#":
			continue
		dist = [[-1 for a in range(w)]for b in range(h)]
		q = queue.Queue()
		q.put([si,sj])
		dist[si][sj]=0
		while not q.empty():
			nowi,nowj = q.get()
			for ne in range(4):
				nexti,nextj = nowi+dx[ne],nowj+dy[ne]
				if nexti<0 or nexti>=h or nextj<0 or nextj>=w:
					continue
				if dist[nexti][nextj] != -1 or s[nexti][nextj]=="#":
					continue
				dist[nexti][nextj] = dist[nowi][nowj]+1
				q.put([nexti,nextj])
				ans = max(ans,dist[nexti][nextj])
print(ans)