from collections import deque

h, w = map(int, input().split())
m = [list(input()) for _ in range(h)]
D = [(-1, 0), (0, -1), (1, 0), (0, 1)]


def bfs(i, j):
    dist = [[0] * w for _ in range(h)]
    que = deque()
    que.append((i, j))

    while que:
        nx, ny = que.pop()
        for dx, dy in D:
            if nx + dx < 0 or ny + dy < 0 or nx + dx >= h or ny + dy >= w:
                continue
            if m[nx + dx][ny + dy] == "#":
                continue
            if dist[nx + dx][ny + dy] != 0:
                continue

            que.appendleft((nx + dx, ny + dy))
            dist[nx + dx][ny + dy] = 1 + dist[nx][ny]
    mx = 0
    for i in dist:
        mx = max(mx, max(i))
    return mx


ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, bfs(i, j))

print(ans)
