from collections import deque

h, w = map(int, input().split())
h += 2; w += 2
maze = ["#" + input() + "#" for _ in range(h-2)]
guard = "#" * (w)
maze.insert(0, guard)
maze.append(guard)

dxy = [(0,1),(1,0),(0,-1),(-1,0)]
ans = 0

for y in range(h):
    for x in range(w):
        if maze[y][x] == "#":
            continue
        dist = [[0] * w for _ in range(h)]
        visited = [[0] * w for _ in range(h)]
        visited[y][x] = 1
        q = deque([(x, y)])
        while q:
            x, y = q.popleft()
            for dx, dy in dxy:
                nx, ny = x+dx, y+dy
                if maze[ny][nx] == "#":
                    continue
                if visited[ny][nx]:
                    continue
                visited[ny][nx] = 1
                dist[ny][nx] = dist[y][x] + 1
                q.append((nx, ny))

print(max(max(d) for d in dist))