from collections import deque
h,w=map(int,input().split())
G=[["#"]*(w+2) for i in range(h+2)]
for i in range(1,h+1):
  G[i]=["#"]+list(input())+["#"]
ans=0
for sx in range(1,h+1):
  for sy in range(1,w+1):
    B=[[0]*(w+2) for i in range(h+2)]
    for i in range(h+2):
      for j in range(w+2):
        if G[i][j]=="#":
          B[i][j]=1
    INF=10**4
    A=[[INF]*(w+2) for i in range(h+2)]
    C=[-1,1,0,0]
    D=[0,0,-1,1]
    A[sx][sy]=0
    E=deque([sx,sy])
    while len(E)>0:
      x=E[0]
      E.popleft()
      y=E[0]
      E.popleft()
      for i in range(4):
        if B[x+C[i]][y+D[i]]==0:
          A[x+C[i]][y+D[i]]=A[x][y]+1
          a=A[x+C[i]][y+D[i]]
          B[x+C[i]][y+D[i]]=1
          E.append(x+C[i])
          E.append(y+D[i])
    if ans<a:
      ans=a
print(ans)