H,W=map(int,input().split())
S=[list(input()) for i in range(H)]
m=0

for y in range(H):
  for x in range(W):
    if S[y][x]=="#":
      continue
    D=[[400]*W for i in range(H)]
    D[y][x]=0
    q=[]
    q.append([x,y])
    while len(q)>0:
      c=list(q.pop(0))
      for dx,dy in [[-1,0],[1,0],[0,-1],[0,1]]:
        if c[1]+dy<0 or c[1]+dy>=H:
          continue
        if c[0]+dx<0 or c[0]+dx>=W:
          continue
        if S[c[1]+dy][c[0]+dx]==".":
          if D[c[1]+dy][c[0]+dx]>D[c[1]][c[0]]+1:
            D[c[1]+dy][c[0]+dx]=D[c[1]][c[0]]+1
            q.append([c[0]+dx,c[1]+dy])
    A=[[D[y][x] if D[y][x]!=400 else -1 for x in range(W)] for y in range(H)]
    m=max(m,max(max(A)))
print(m)