from copy import deepcopy as dcopy
h,w=map(int,input().split())
s=[list(input()) for _ in range(h)]
def mostfar(sx,sy,s):
  if s[sy][sx]=='#':
    return -1
  mx=len(s)*len(s[0])-1
  l=[[mx if s[j][i]=='.' else -1 for i in range(w)] for j in range(h)]
  step=0
  l[sy][sx]=0
  tmp=dcopy(l)
  while 1:
    step+=1
    for x in range(w):
      for y in range(h):
        if l[y][x]==step-1:
          if x!=0:
            l[y][x-1]=min(l[y][x-1],step)
          if x!=w-1:
            l[y][x+1]=min(l[y][x+1],step)
          if y!=0:
            l[y-1][x]=min(l[y-1][x],step)
          if y!=h-1:
            l[y+1][x]=min(l[y+1][x],step)
    if tmp==l:
      break
    tmp=dcopy(l)
  return max([max(r) for r in l])

ans=max(max(mostfar(x,y,s) for x in range(w)) for y in range(h))
print(ans)