import copy

a = 0
def search(N, m, n, i, j, H, W):
    global a
    m[i][j] = n
    if a < n:
        a = n
    if i > 0:
        if N[i-1][j] > N[i][j]+1 and m[i-1][j] != "#":
            search(N, m, n+1, i-1, j, H, W)
    if j > 0:
        if N[i][j-1] > N[i][j]+1 and m[i-1][j] != "#":
            search(N, m, n+1, i, j-1, H, W)
    if H > i+1:
        if N[i+1][j] > N[i][j]+1 and m[i-1][j] != "#":
            search(N, m, n+1, i+1, j, H, W)
    if W > j+1:
        if N[i][j+1] > N[i][j]+1 and m[i-1][j] != "#":
            search(N, m, n+1, i, j+1, H, W)

H, W = map(int, input().split())
maze = []
for i in range(H):
    l = list(input())
    maze += [l]

for i in range(H):
    for j in range(W):
        if maze[i][j] == ".":
            N = [[1000000000]*H]*W
            N[i][j] = 0
            search(N, maze, 0, i, j, H, W)
print(a)