import numpy as np
from collections import deque
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
moves = ((1, 0), (0, 1), (0, -1), (-1, 0))

def bfs(sy, sx):
  dist = [[-1]*W for _ in range(H)]
  dist[sy][sx] = 0
  q = deque([[sy, sx]])

  while q:
    y, x = q.popleft()
    for dy, dx in moves:
      ny = y + dy
      nx = x + dx
      if 0 <= ny < H and 0 <= nx < W and dist[ny][nx] == -1 and S[ny][nx] == '.':
        dist[ny][nx] = dist[y][x] + 1
        q.append([ny, nx])

  return dist

d = bfs(0, 0)
d = np.array(d)
ans = 0
for i in range(H):
  for j in range(W):
    if S[i][j] != '#':
      d = bfs(i, j)
      d = np.array(d)
  ans = max(ans, np.max(d))
print(ans)


