import numpy as np
h,w=map(int,input().split())
s=[[0 for i in range(w)] for j in range(h)]
for i in range(h):
	s[i]=list(input())
# h,w=3,3
# s=[['.', '.', '.'], ['.', '.', '.'], ['.', '.', '.']]
v=[[1000000 for i in range(w)] for j in range(h)]
s=np.array(s)
v=np.array(v)
def search(H,W,p):
	m=0
	if H<h-1 and s[H+1][W]=='.' and v[H+1][W]>p+1:
		v[H+1][W]=p+1
		m=p+1
	if H>0 and s[H-1][W]=='.' and v[H-1][W]>p+1:
		v[H-1][W]=p+1
		m=p+1
	if W>0 and s[H][W-1]=='.' and v[H][W-1]>p+1:
		v[H][W-1]=p+1
		m=p+1
	if W<w-1 and s[H][W+1]=='.' and v[H][W+1]>p+1:
		v[H][W+1]=p+1
		m=p+1
	return m

def dijk():
	f=False
	global P
	global M
	for i in range(h):
		for j in range(w):
			if v[i][j]==P:
				m=search(i,j,P)
				M=max(m,M)
				f=True

	P+=1
	if f==False:
		return 0
	dijk()
M_=0
for i in range(h):
	for j in range(w):
		v[i][j]=0
		P=0
		M=0
		if s[i][j]!='.':
			continue
		dijk()
		M_=max(M,M_)
		v=[[1000000 for i in range(w)] for j in range(h)]
print(M_)