import sys
from collections import deque

H, W = map(int, input().split())
S = [input() for a in range(H)]
dy = [1, 0, -1, 0]
dx = [0, 1, 0, -1]

answer = 0

for s_y in range(H):
  for s_x in range(W):
    d = [[ 0 for b in range(W)] for a in range(H)]
    q = deque([[s_y, s_x]])
    d[s_y][s_x] = 0
    while len(q) > 0:
      y, x = q.popleft()
      for i in range(4):
        ny = y + dy[i]
        nx = x + dx[i]
        if 0 <= nx and nx <= W-1 and 0 <= ny and ny <= H-1 and S[ny][nx] == '.' and d[ny][nx] == 0:
          q.append([ny, nx])
          d[ny][nx] = d[y][x]+1
    for i in range(H):
      answer = max(answer, max(d[i]))
print(answer)