from collections import deque
 
h, w = map(int, input().split())
a = ''.join(input() + '#' for _ in range(h))
n = len(a)
b = ['#'] * w
q = deque()
d = -1, 1, -w - 1, w + 1
r = 0
for i in range(n):
  if a[i] == '.':
    b[:-w] = a
    b[i] = 0
    q.append(i)
    while(q):
      i = q.popleft()
      r = max(r, b[i])
      for j in d:
        j += i
        if b[j] == '.':
          b[j] = b[i] + 1
          q.append(j)
print(r)
