from collections import deque
h, w = map(int, input().split())
l = [list(input()) for _ in range(h)]

#四方向の移動用
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]


def bfs(sx, sy):
    d = [[-1]*w for i in range(h)]
    que = deque([])
    que.append((sx, sy))
    d[sy][sx] = 0

    while que:
        p = que.popleft()

        for i in range(4):
            nx = p[0]+dx[i]
            ny = p[1]+dy[i]

            if (0 <= nx < w) and (0 <= ny < h) and (l[ny][nx] != "#") and (d[ny][nx] == -1):
                que.append((nx, ny))
                d[ny][nx] = d[p[1]][p[0]] + 1

    return max(sum(d, []))


ans = 0
for sy in range(h):
    for sx in range(w):
        temp = bfs(sx, sy)
        if ans < temp:
            ans = temp
print(ans)
