import queue

h, w = map(int, input().split())
s = '#'*(w+2)
for _ in range(h):
    s += '#' + input() +'#'
s += '#'*(w+2)

ans = 0
for i in range((w+2)*(h+2)):
    if s[i] == '#':
        continue
    dist = [10**5]*(w+2)*(h+2)
    dist[i] = 0
    q = queue.Queue()
    q.put(i)
    while not q.empty():
        x = q.get()
        for j in (1, -1, w+2, -w-2):
            if s[j+x] =='#':
                continue
            if dist[j+x] > dist[x] + 1:
                dist[j+x] = dist[x] + 1
                q.put(j+x)
    for k in range((w+2)*(h+2)):
      if dist[k] != 10**5:
        ans = max(ans, dist[k])

print(ans)

