h,w=map(int,input().split())
m=[]
for i in range(h):
  m.append(list(map(lambda x:int(x=="#"),list(input())))+[1,1])
m+=[[1 for i in range(w+2)]]*2
mx=0
d=[(1,0),(-1,0),(0,1),(0,-1)]
for x in range(h):
  for y in range(w):
        if m[x][y]:
          continue
        s=[(x,y)]
        c=-1
        v=[[0 for i in range(w)] for i in range(h)]
        v[x][y]=1
        while s:
          ns=[]
          for i in s:
            for j in d:
              if m[i[0]+j[0]][i[1]+j[1]] or v[i[0]+j[0]][i[1]+j[1]]:
                continue
              v[i[0]+j[0]][i[1]+j[1]]=1
              ns.append((i[0]+j[0],i[1]+j[1]))
          s=ns
          c+=1
        mx=max(mx,c)
print(mx)
          
      