import numpy as np

def chk_route(c,s,T):
    global H,W,R
    mx = H*W
    #print(c)
    #print(T)
    flg = 0
    T[c[0]][c[1]]=s
    if R[c[0]][c[1]] > s:
        R[c[0]][c[1]] = s

    if c[0] != H-1:
        #if T[c[0]+1][c[1]]!=1 and T[c[0]+1][c[1]]!=s-1 and T[c[0]+1][c[1]]!=2:
        if T[c[0]+1][c[1]]==0:
            flg=1
            B=T.copy()
            chk_route([c[0]+1,c[1]],s+1,B)
    if c[0] != 0:
        #if T[c[0]-1][c[1]]!=1 and T[c[0]-1][c[1]]!=s-1 and T[c[0]-1][c[1]]!=2:
        if T[c[0]-1][c[1]]==0:
            flg=1
            B=T.copy()
            chk_route([c[0]-1,c[1]],s+1,B)
    if c[1] != W-1:
        #if T[c[0]][c[1]+1]!=1 and T[c[0]][c[1]+1]!=s-1 and T[c[0]][c[1]+1]!=2:
        if T[c[0]][c[1]+1]==0:
            flg=1
            B=T.copy()
            chk_route([c[0],c[1]+1],s+1,B)
    if c[1] != 0:
        #if T[c[0]][c[1]-1]!=1 and T[c[0]][c[1]-1]!=s-1 and T[c[0]][c[1]-1]!=2:
        if T[c[0]][c[1]-1]==0:
            flg=1
            B=T.copy()
            chk_route([c[0],c[1]-1],s+1,B)

    if flg == 0:
        #print(T)
        #r=np.count_nonzero(T==2)
        if R[c[0]][c[1]] > s:
            R[c[0]][c[1]] = s
        #return s
    if s==2: pass #return mx
        #T=np.copy(B)
H,W= [int(x) for x in input().split()]
n=[]
#T = [[0] * W for i in range(H)]
T=np.zeros((H,W),dtype=int)
MX = H*W
R=np.full((H,W),MX,dtype = int)
#R = [[15] * W for i in range(H)]
for i in range(H):
  n=input()
  for j in range(W):
    if n[j]=="#": T[i][j]=1
#print(T)
d=0
for i in range(H):
    for j in range(W):

        if T[i][j] =='1':continue

        c=[i,j]
        B=T.copy()
        R=np.full((H,W),MX,dtype = int)
        chk_route(c,int(2),B)

        d = max(d,np.max(R[np.where(R<MX)]))

        #b= b[np.where(b[:,22].astype(float) > 0)]
print(d-2)
#print(mx)

