from collections import deque
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
cost = [[600] * w for _ in range(h)]
nb = [(-1, 0), (0, -1), (1, 0), (0, 1)]
ans = 0


def bfs(sx, sy, gx, gy):
    q = deque([(sx, sy)])
    cost[sy][sx] = 0

    while q != deque([]):
        x, y = q.popleft()
        for dx, dy in nb:
            nx = x + dx
            ny = y + dy
            if 0 <= nx and nx < w and 0 <= ny and ny < h and s[ny][nx] == "." and cost[ny][nx] == 600:
                q.append((nx, ny))
                cost[ny][nx] = cost[y][x] + 1
                if nx == gx and ny == gy:
                    return cost[gy][gx]


ans = 0
for i in range(h):
    for j in range(w):
        for k in range(h):
            for l in range(w):
                cost = [[600] * w for _ in range(h)]
                tmp = bfs(j, i, l, k)
                if tmp != None:
                    ans = max(tmp, ans)

print(ans)