from collections import deque
from itertools import combinations

H, W = map(int, input().split())
c = [list(input()) for _ in range(H)]

points = []
for i in range(H):
    for j in range(W):
        if c[i][j] == '.':
            points.append((j, i))

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]        
def bfs(start, goal):
    s = [[-1] * W for _ in range(H)]
    d = [[0] * W for _ in range(H)]

    sx, sy = start
    gx, gy = goal

    que = deque([])
    que.append((sx, sy))
    s[sy][sx] = 1
    
    while que:
        x, y = que.popleft()
        s[y][x] = 1

        if x == gx and y == gy:
            return d[y][x]
        
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]

            if 0 <= nx < W and 0 <= ny < H and s[ny][nx] != 1 and c[ny][nx] == '.':
                que.append((nx, ny))
                d[ny][nx] = d[y][x] + 1

ans = 0
for comb in combinations(points, 2):
    start, goal = comb
    ans = max(ans, bfs(start, goal))

print(ans)