from collections import deque
import itertools
import copy

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


def bfs(maze, s, g):
    q = deque()
    q.append((s, 0))

    maze[s[0]][s[1]] = "#"

    while len(q) > 0:
        p, depth = q.popleft()

        if p == g:
            return depth

        # ikerutoko
        next_pos = []
        if 0 <= p[0] - 1 < H and maze[p[0] - 1][p[1]] != "#":
            next_pos.append((p[0] - 1, p[1]))
        if 0 <= p[0] + 1 < H and maze[p[0] + 1][p[1]] != "#":
            next_pos.append((p[0] + 1, p[1]))
        if 0 <= p[1] - 1 < W and maze[p[0]][p[1] - 1] != "#":
            next_pos.append((p[0], p[1] - 1))
        if 0 <= p[1] + 1 < W and maze[p[0]][p[1] + 1] != "#":
            next_pos.append((p[0], p[1] + 1))

        # print(next_pos, q)

        for pos in next_pos:
            maze[pos[0]][pos[1]] = "#"
            q.append((pos, depth + 1))

    return -1


kaisuu = 0
for s in itertools.product(range(H), range(W)):
    for g in itertools.product(range(H), range(W)):
        if s == g or S[s[0]][s[1]] == "#" or S[g[0]][g[1]] == "#":
            continue

        maze = copy.deepcopy(S)
        k = bfs(maze, s, g)
        kaisuu = max(kaisuu, k)

print(kaisuu)
