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

#output
import numpy as np
INF = 10**5
dp = np.full((H, W), INF)

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

def clear_maze(sx, sy, gx, gy, maze):
    def bfs():
        q = []
        q.insert(0, (sx, sy))
        dp[sx, sy] = 0

        while len(q):
            x, y = q.pop()

            if x == gx and y == gy:
                break

            for i in range(0, 4):
                nx, ny = x + dx[i], y + dy[i]

                if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] != "#" and dp[nx, ny] == INF:
                    q.insert(0, (nx, ny))
                    dp[nx, ny] = dp[x, y] + 1
        return dp[gx, gy]
    return bfs()

L = []
for h1 in range(H):
    for h2 in range(H):
        for w1 in range(W):
            for w2 in range(W):
                if h1 != "#" and h2 != "#" and w1 != "#" and w2 != "#":
                    dp = np.full((H, W), INF)
                    p = clear_maze(h1, w1, h2, w2, S)
                    if p != INF:
                        L.append(p)
print(max(L))