H,W=map(int, input().split())
for i in range(H):
  S[i]=list(input().split())
  
def make_a(X,i,j):
  a=[0]*4
  if (i-1)>=0:
    a[0]=X[i-1][j]
  else:
    a[0]=H*W
  if (i+1)<=H-1:
    a[1]=X[i+1][j]
  else:
    a[1]=0
  if (j-1)>0:
    a[2]=X[i][j-1]
  else:
    a[2]=0
  if (j+1)<=W-1:
    a[3]=X[i][j+1]
  else:
    a[3]=0
  return a

def len_path(i,j):
  T=[[0]*W]*H
  for S[c][d] in S:
    if S[c][d]=="#":
      T[c][d]=H*W
  T[i][j]=1
  for s in range(H*W):
    for T[k][l] in T:
      if T[k][l]==0:
        if not min(make_a(T,k,l))==0:
          T[k][l]=make_a(T,k,l)+1
  if max(T)<H*W:
    return max(T)-1
  else:
    return sorted(set(T))[-2]-1

Q=[[0]*W]*H  
for i in range(H):
  for j in range(W):
    Q[i][j]=len_path(i,j)
print(max(Q))