from collections import deque
h,w = list(map(int, input().split()))
maze = [ input() for _ in range(h)]

def bfs(que):
  d = 0
  while que:
    y,x = que.popleft()
    d = dist[y][x]
    for dy, dx in ((0,1),(1,0),(0,-1),(-1, 0)):
      next_y = y + dy
      next_x = x + dx
      if(0 <= next_y and next_y < h and 0 <= next_x and next_x < w and maze[next_y][next_x] != "#" and dist[next_y][next_x] == -1):
        que.append((next_y,next_x))
        dist[next_y][next_x] = d + 1
  return d

ans = -1
for i in range(h):
  for j in range(w):
    que = deque()
    dist = [ [-1]*w for _ in range(h) ]
    dist[i][j] = 0
    que.append((i, j))
    ans = max([ans, bfs(que)])
print(ans)

