import numpy as np

h, w = map(int,input().split())

maze = []
for i in range(h):
  ip = input()
  new_ip = list(ip)
  maze.append(new_ip)
ans_li = []
for i in range(h):
  for j in range(w):
    li = [[-1 for p in range(w)] for q in range(h)]
    li[i][j] = 0
    for k in range(20):
      for p in range(h):
        for q in range(w):
          if li[p][q] != -1 and p + 1 <= h - 1:
            if (li[p + 1][q] >= li[p][q] or li[p + 1][q] == -1) and maze[p+1][q] == ".":
              li[p + 1][q] = li[p][q] + 1
          if li[p][q] != -1 and p - 1 >= 0:
            if (li[p - 1][q] >= li[p][q] or li[p - 1][q] == -1) and maze[p-1][q] == ".":
              li[p - 1][q] = li[p][q] + 1
          if li[p][q] != -1 and q + 1  <= w - 1:
            if (li[p][q + 1] >= li[p][q] or li[p][q + 1] == -1) and maze[p][q+1] == ".":
              li[p][q + 1] = li[p][q] + 1
          if li[p][q] != -1 and q - 1 >= 0:
            if (li[p][q - 1] >= li[p][q] or li[p][q - 1] == -1) and maze[p][q-1] == ".":
              li[p][q - 1] = li[p][q] + 1
          
    ans_li.append(np.max(li))

print(max(ans_li))
