from collections import deque

H, W = map(int, input().split())

S = [['#'] * (W+2)]
for _ in range(H):
  tmp = ['#'] + list(input()) + ['#']
  S.append(tmp)
S.append(['#'] * (W+2))

move = [[1,0], [-1,0], [0,1], [0,-1]]

ans = 0
for X in range(1, H+1):
  for Y in range(1, W+1):
    if S[x][Y] == '#':
      continue
    check = [[-1] * (W+2) for _ in range(H+2)]
    check[X][Y] = 0
    que = deque()
    que.append([X, Y])
    while que:
      tmp = que.popleft()
      x = tmp[0]
      y = tmp[1]
      flag = True
      for dx, dy in move:
        nx = x + dx
        ny = y + dy
        if S[nx][ny] == '.' and check[nx][ny] == -1:
          que.append([nx, ny])
          check[nx][ny] = check[x][y] + 1
          flag =False
      if flag:
        ans = max(ans, check[x][y])
print(ans)