from scipy.sparse import csr_matrix, csgraph
H, W = map(int, input().split())
maze = "".join(input() for _ in range(H))
data = []
row = []
column = []
for n in range(H * W):
    if maze[n] == "#":
        continue
    r, c = divmod(n, W)
    if c and maze[n - 1] == ".":
        data.append(1)
        row.append(n)
        column.append(n - 1)
    if c != W - 1 and maze[n + 1] == ".":
        data.append(1)
        row.append(n)
        column.append(n + 1)
    if r and maze[n - W] == ".":
        data.append(1)
        row.append(n)
        column.append(n - W)
    if r != H - 1 and maze[n + W] == ".":
        data.append(1)
        row.append(n)
        column.append(n + W)
dist = csgraph.shortest_path(csr_matrix((data, (row, column)), dtype="i8", shape=(H * W, H * W)), directed=False)
print(int(dist[dist < 401].max()))