from collections import deque
h, w = map(int, input().split())
s = ['#' * (w+2)] + ['#' + input() + '#' for _ in range(h)] + ['#' * (w+2)]

ans = 0
INF = 111111

for i in range(h+1):
  for j in range(w+1):
    if s[i][j] == '#':
      continue
    visited = [[0] * (w+2) for _ in range(h+2)]
    visited[i][j] = 1
    max_s = 0
    dq = deque([(i, j, 0)])

    while dq:
      ci, cj, step = dq.popleft()
      if step > max_s:
        max_s = step
      step += 1

      for di, dj in ((ci+1, cj), (ci, cj+1), (ci-1, cj), (ci, cj-1)):
        if s[di][dj] == '#' or visited[di][dj] == 1:
          continue
        visited[di][dj] = 1
        dq.append((di, dj, step))
    ans = max(max_s, ans)

print(ans)