# coding: utf-8
#-------------------------------------------------------------------
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
H,W = map(int, input().split())			# "5 7" -> ["5", "7"] -> 5, 7 => N=5,K=7

S=[ "" for _ in range(H+2) ]
#p(S)

S[0]="#"*(W+2)
S[H+1]="#"*(W+2)
for h in range(1,H+1):
	s = input()
	S[h] = "#" + s + "#"

#p(S)

XY=[[1,0],[-1,0],[0,1],[0,-1]]

INF=float("inf") # 正の無限大
ans=0

from collections import deque

for h in range(1,H+1):
	for w in range(1,W+1):

		if S[h][w]=="#": continue

		M=[[ INF for w in range(W+2) ] for h in range(H+2)]
		M[h][w]=0

		Q = deque()
		Q.append([h,w])
		mmax=0

		#p("Q=",Q)
		
		while Q:
			h,w=Q.pop()
			
			if S[h][w]=="#": continue
			
			m = M[h][w]
			mmax=max(mmax,m)
			for x,y in XY:
				if S[h+y][w+x]=="#": continue
				
				if M[h+y][w+x] > (m+1):
					M[h+y][w+x] = m+1
					Q.append([h+y,w+x])
					mmax=max(mmax,m+1)

			#p("h,w,Q,m=",h,w,Q,m)

		for MH in M:
			for m in MH:
				if m==INF: continue
				ans=max(ans,m)


#for m in M:
#	print(m)

print(ans)