import copy

H, W = map(int, input().split())
S = [[0 if c == '.' else 1 for c in input()] for _ in range(H)]

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

def bfs(y, x):
    q = [[y,x,0]]
    ST = copy.deepcopy(S)
    res = -1
    while len(q):
        ST[y][x] = 1
        y, x, d = q.pop(0);
        res = max(res, d)
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if not (0 <= ny <= H-1 and 0 <= nx <= W-1): continue
            if ST[ny][nx] == 1: continue
            q.append([ny,nx,d+1])
    return res

ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == 1: continue
        ans = max(ans, bfs(i,j))
print(ans)