import numpy as np

H, W = map(int, input().split(' '))
maze = []
for i in range(H):
    maze.append(input())


def search(visit, queue):
    while len(queue) > 0:
        x, y, d = queue.pop(0)
        visit[y][x] = d
        for i in range(3):
            dy = y + i - 1
            if dy == H or dy == -1:
                continue
            for j in range(3):
                if i == 0 and j == 0:
                    continue
                if i == 2 and j == 2:
                    continue
                if i == 0 and j == 2:
                    continue
                if i == 2 and j == 0:
                    continue
                dx = x + j - 1
                if dx == W or dx == -1:
                    continue
                if visit[dy][dx] > 0:
                    continue
                if maze[dy][dx] == '.':
                    queue.append((dx, dy, visit[y][x] + 1))


best = 0
for i in range(H):
    for j in range(W):
        visit = np.zeros((H, W), dtype=np.int32)
        search(visit, [(j, i, 0)])
        print(visit)
        dist = np.max(visit)
        if dist > best:
            best = dist
print(best - 1)