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
adj=[[1e9 for i in range(h * w)] for j in range(h*w)]
for i in range(h*w):
	c = i%w
	r=i//w
	if g[r][c] == '#':
		continue
	adj[i][i]=0
	if c + 1 < w and g[r][c+1] =='.':
		adj[i][i+1]=1
	if c-1 >=0 and g[r][c-1]=='.':
		adj[i][i-1]=1
	if r+1<h and g[r+1][c]=='.':
		adj[i][i+w]=1
	if r-1>=0 and g[r-1][c]=='.':
		adj[i][i-w]=1

tmax = 0
for k in range(h*w):
	for i in range(w*h):
		for j in range(h*w):
			if g[k//w][k%w] == '#' or g[i//w][i%w] == '#' or g[j//w][j%w]=='#':
				continue
			adj[i][j]=min(adj[i][j], adj[i][k] + adj[k][j])
for i in range(h*w):
	for j in range(h*w):
		if adj[i][j] < 1e9:
			tmax=max(tmax, adj[i][j])
print(tmax)
