# from collections import deque
H, W = list(map(int, input().split()))
# dp = [[1000 for _ in range(W)] for _ in range(H)]

S = [['#']*(W+2)] + [['#']+list(input())+['#'] for h in range(H)] + [['#']*(W+2)]
# S = (H+2, W+2)
# S =  [input().split() for h in range(H)]
max_n = 0

for h1 in range(1,H+1):
  for w1 in range(1,W+1):
    if S[h1][w1] == '#':
      continue
    distance = [[1000 for _ in range(W+2)] for _ in range(H+2)]
    distance[h1][w1] = 0
    que = []
    que.append([h1,w1])
    que_i = 0
    while que_i < len(que):
      h, w = que[que_i]
      if S[h-1][w] == '.' and [h-1, w] not in que:
        que.append([h-1,w])
        distance[h-1][w] = min(distance[h][w] + 1, distance[h-1][w])
      if S[h+1][w] == '.' and [h+1, w] not in que:
        que.append([h+1,w])
        distance[h+1][w] = min(distance[h][w] + 1, distance[h+1][w])
      if S[h][w-1] == '.' and [h, w-1] not in que:
        que.append([h,w-1])
        distance[h][w-1] = min(distance[h][w] + 1, distance[h][w-1])
      if S[h][w+1] == '.' and [h-1, w+1] not in que:
        que.append([h,w+1])
        distance[h][w+1] = min(distance[h][w] + 1, distance[h][w+1])
      que_i += 1
    hw_max_n = 0
    for h2 in range(1,H+1):
      for w2 in range(1,W+1):
        if distance[h2][w2] != 1000:
          hw_max_n = max(hw_max_n, distance[h2][w2])
    max_n = max(max_n, hw_max_n)
print(max_n)