import queue
INF = 100000000

H, W = list(map(int,input().split()))
S = [list(input()) for i in range (H)]

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

def bfs(sx, sy):
    d = [[0 for i in range(W)] for j in range(H)]
    d[sx][sy] = 0
    max_d = 0

    q = queue.Queue()
    q.put([sx, sy])

    while not q.empty():
        p = q.get()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if (0 <= nx) & (nx < H) & (0 <= ny) & (ny < W):
                if (S[nx][ny] != "#") & (d[nx][ny] == 0):
                    d[nx][ny] = d[p[0]][p[1]] + 1
                    q.put([nx, ny])
                    max_d = max(max_d, d[nx][ny])

    return max_d

res = 0
for sx in range(H):
    for sy in range(W):
        res = max(res, bfs(sx, sy))

print(res)
