from pprint import pprint
from collections import deque
import sys
import copy
input = sys.stdin.readline

sys.setrecursionlimit(10000)

H, W = map(int, input().split())


maze = []
for i in range(H):
    w_maze = list(input().replace('\n', ''))
    maze.append(w_maze)

# print(maze)


def solve_maze(maze, start, goal):
    q = deque()

    q.append((0, start[0], start[1]))

    # pprint(q)

    while q:
        count, y, x = q.popleft()
        # print(count, y, x)
        for dy, dx in ((-1, 0), (1, 0), (0, 1), (0, -1)):
            # print('now_position:{} {}, next_direction:{} {}, next_position:{} {}'.format(y, x, dy, dx, y + dy, x + dx))
            # print('y+dy, x+dx, maze[y+dy][x+dx])
            if y + dy < 0 or y + dy > H - 1 or x + dx < 0 or x + dx > W - 1:
                continue
            elif maze[y + dy][x + dx] == "#":
                # 壁に対しても何もしない
                continue
            elif maze[y + dy][x + dx] == "x":
                # 探索済みは何もしない
                continue
            elif y + dy == goal[0] and x + dx == goal[1]:
                return count + 1

            maze[y + dy][x + dx] = 'x'
            # print(maze)

            q.append((count + 1, y + dy, x + dx))
    return -1


max_move_count = 0

# startのループ
for y in range(H):
    for x in range(W):
        if maze[y][x] != '.':
            continue
        else:
            # goalのループ
            for goal_y in range(H):
                for goal_x in range(W):
                    if maze[goal_y][goal_x] != '.':
                        continue
                    else:
                        move_count = solve_maze(copy.deepcopy(maze), [y, x], [goal_y, goal_x])
                        max_move_count = max(max_move_count, move_count)

print(max_move_count)

