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

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

inf = float('inf')

import queue

ans = 0

for h in range(H):
    for w in range(W):
        if S[h][w] != '#':
            q = queue.Queue()
            d = [[inf for _ in range(W)] for _ in range(H)]
            # 距離を保存
            q.put([h, w])
            d[h][w] = 0
            # スタートをキューに、距離を0に
            while not q.empty():
                p = q.get()
                # if p == g:
                #     break
                for i in range(4):
                    nx = p[1] + dx[i]
                    ny = p[0] + dy[i]
                    if nx >= 0 and nx < W and ny >= 0 and ny < H and S[ny][nx] != '#' and d[ny][nx] == inf:
                        q.put([ny, nx])
                        d[ny][nx] = d[p[0]][p[1]] + 1
            for h in range(H):
                for w in range(W):
                    if d[h][w] != inf:
                        ans = max(ans, d[h][w])

print(ans)
