INF=10**9+7
H,W=map(int,input().split())
S=list()
q=list()

S.append(["#"]*(W+2))
for i in range(H):
  S.append(["#"]+list(input())+["#"])
S.append(["#"]*(W+2))


m=0
for y in range(1,H+1):
  for x in range(1,W+1):
    if S[y][x]=="#":
      continue
    D=[[INF]*(W+2) for _ in range(H+2)]
    D[y][x]=0
    q.clear()
    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]]:
        ny,nx=c[1]+dy,c[0]+dx
        if S[ny][nx]=="." and D[ny][nx]==INF:
          D[ny][nx]=D[c[1]][c[0]]+1
          q.append([nx,ny])
          m=max(m,D[ny][nx])
print(m)
