from collections import deque

h,w=map(int,input().split())
S=[]
for _ in range(h):
  s=input()
  sl=[]
  for i in range(w):
    sl.append(s[i])
  S.append(sl)
ans=-1
check=[]
for i in range(h):
  for j in range(w):
    for k in range(h):
      for l in range(w):
        if [k,l,i,j] in check:
          continue
        if S[i][j]=='.' and S[k][l]=='.':
          sy,sx,gy,gx=i,j,k,l
          W=[[-1 for i in range(w)] for j in range(h)]
          Q=deque()
          Q.append([sy,sx])
          W[sy][sx]=0
          while Q:
            py,px=Q.popleft()
            for p,q in [[-1,0],[0,-1],[1,0],[0,1]]:
              ny,nx=py+p,px+q
              if 0<=ny<=h-1 and 0<=nx<=w-1 and S[ny][nx]=='.':
                if W[ny][nx]==-1:
                  W[ny][nx]=W[py][px]+1
                  Q.append([ny,nx])
          check.append([i,j,k,l])
          ans=max(ans,W[gy][gx])
print(ans)