H, W = map(int, input().split())
S = []

for ix in range(H):
    S.append(list(input()))

DMX = 500
dp = [[10**9 for _ in range(DMX)] for __ in range(DMX)]

def tid(x,y):
    return x*W+y

for i in range(DMX):
    dp[i][i] = 0

D = ((1,0), (0,1), (-1,0), (0, -1))
for ix in range(H):
    for jy in range(W):
        if S[ix][jy] == '#':
            continue
        for dx, dy in D:
            nx = ix + dx
            ny = jy + dy

            if nx < 0 or ny < 0 or nx >= H or ny >= W or S[nx][ny] == '#':
                continue

            dp[tid(ix,jy)][tid(nx, ny)] = 1
            dp[tid(nx,ny)][tid(ix, jy)] = 1

# Floyd-Warshall
V = H * W
for v in range(V):
    for i in range(V):
        for j in range(V):
            t = dp[i][v] + dp[v][j]
            if dp[i][j] > t:
                dp[i][j] = t

ans = 0
for x in range(H):
    for y in range(W):
        if S[x][y] == '#':
            continue
        for x2 in range(H):
            for y2 in range(W):
                if S[x2][y2] == '#':
                    continue
                t = dp[tid(x,y)][tid(x2,y2)]
                if t > ans:
                    ans = t

print(ans)