#input
H, W = map(int, input().split())
import numpy as np

S = np.full((H, W), ".")
for i in range(H):
    x = input()
    for j in range(W):
        if x[j] == "#":
            S[i, j] = "#"

#output
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):
                dp = np.full((H, W), INF)
                p = clear_maze(h1, w1, h2, w2, S)
                if p != INF:
                    L.append(p)

print(max(L))