from itertools import combinations, product
import copy
H, W = map(int, input().split())


def search_steps(maze, cy, cx, gy, gx, step):
    if (cy, cx) == (gy, gx):
        return step
    ss = []
    for dy, dx in ((0, 1), (0, -1), (1, 0), (-1, 0)):
        ny, nx = cy + dy, cx + dx
        new_maze = copy.deepcopy(maze)
        new_maze[cy][cx] = "#"
        if 0 <= ny <= H - 1 and 0 <= nx <= W - 1 and maze[ny][nx] == ".":
            s = search_steps(new_maze, ny, nx, gy, gx, step + 1)
            if s >= 0:
                ss.append(s)

    if len(ss) == 0:
        return -1
    else:
        mss = min(ss)
        return min(ss) if mss >= 0 else -1


S = [0] * H
for i in range(H):
    S[i] = list(input())

max_steps = 0
for s, g in combinations(range(H * W), 2):
    sy, sx = s // W, s % W
    gy, gx = g // W, g % W
    if S[sy][sx] == "#" or S[gy][gx] == "#":
        continue

    steps = search_steps(copy.deepcopy(S), sy, sx, gy, gx, 0)
    if steps > max_steps:
        max_steps = steps
    if steps == H * W - 1:
        break

print(max_steps)
