import numpy as np
import queue
H, W = map(int, input().split())
S = [input() for _ in range(H)]
reach = [[False] * W for i in range(H)]
step = np.ones((H, W)) * (-1)
m = 0


def dfs(x, y, s):
    if x < 0 or W <= x or y < 0 or H <= y:
        return None
    if reach[y][x]:
        return None
    if S[y][x] == '#':
        return None

    reach[y][x] = True
    step[y, x] = min(s, step[y, x])

    dfs(x+1, y, s+1)
    dfs(x-1, y, s+1)
    dfs(x, y-1, s+1)
    dfs(x, y+1, s+1)


q = queue.Queue()

for sh in range(H):
    for sw in range(W):
        reach = [[False] * W for i in range(H)]
        step = np.ones((H, W)) * (-1)
        #dfs(sw, sh, 0)
        q.put((sw, sh, 0))
        while not q.empty():
            x, y, s = q.get()
            if x < 0 or W <= x or y < 0 or H <= y:
                pass
            elif reach[y][x]:
                pass
            elif S[y][x] == '#':
                pass
            else:
                reach[y][x] = True
                step[y, x] = min(s, step[y, x]) if step[y, x] != -1 else s

                q.put((x+1, y, s+1))
                q.put((x-1, y, s+1))
                q.put((x, y-1, s+1))
                q.put((x, y+1, s+1))

        m = max(m, np.max(step))

print(int(m))
