h,w=map(int,input().split())
ans=-1
s=[]
for i in range(h):
	ss=input()
	s.append(ss)
from collections import deque as dq
for i in range(h):
	for j in range(w):
		dis=[[10**3 for _ in range(w)]for _ in range(h)]
		dis[i][j]=0
		queue=dq([[i,j]])
		while queue:
			r=queue.popleft()
			if r[0]+1<h:
				if s[r[0]+1][r[1]]=="." and dis[r[0]+1][r[1]]==10**3:
					queue.append([r[0]+1,r[1]])
					dis[r[0]+1][r[1]]=dis[r[0]][r[1]]+1
			if r[0]-1>=0:
				if s[r[0]-1][r[1]]=="." and dis[r[0]-1][r[1]]==10**3:
					queue.append([r[0]-1,r[1]])
					dis[r[0]-1][r[1]]=dis[r[0]][r[1]]+1
			if r[1]+1<w:
				if s[r[0]][r[1]+1]=="." and dis[r[0]][r[1]+1]==10**3:
					queue.append([r[0],r[1]+1])
					dis[r[0]][r[1]+1]=dis[r[0]][r[1]]+1
			if r[1]+1>=0:
				if s[r[0]][r[1]-1]=="." and dis[r[0]][r[1]-1]==10**3:
					queue.append([r[0],r[1]-1])
					dis[r[0]][r[1]-1]=dis[r[0]][r[1]]+1
		for k in range(h):
			for l in range(w):
				if dis[k][l]!=10**3:
					ans=max(ans,dis[k][l])
print(ans)
			



			
