from collections import deque
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
ans=-1
dx=[1,0,-1,0]
dy=[0,1,0,-1]
for sy in range(h):
  for sx in range(w):
    for gy in range(h):
      for gx in range(w):
        if sy==gy and sx==gx:
          continue
        if s[sy][sx]=='#' or s[gy][gx]=='#':
          continue
        q=deque()
        q.append((sy,sx,0))
        visited=[[False]*w for i in range(h)]
        visited[sy][sx]=True
        while q:
          y,x,cost=q.pop()
          visited[y][x]=True
          for i in range(4):
            ny,nx=y+dy[i],x+dx[i]
            if ny==gy and nx==gx:
              ans=max(ans,cost)
            if 0<=ny<h and 0<=nx<w and not visited[ny][nx] and s[ny][nx]=='.':
              q.appendleft((ny,nx,cost+1))
print(ans)
