from collections import deque
h, w = map(int, input().split())
maze = []
for _ in range(h):
    maze.append(list(input()))

def clear_maze(sx, sy, gx, gy, maze):
    INF = float('infinity')
    field_x_length = len(maze)
    field_y_length = len(maze[0])
    distance = [[INF for i in range(field_y_length)] for j in range(field_x_length)]

    def bfs():
        queue = deque([(sx, sy)])
        distance[sx][sy] = 0
        dx = [1, 0, -1, 0]
        dy = [0, 1, 0, -1]
        while queue:
            x, y = queue.pop()
            if x == gx and y == gy:
                break
            for i in range(0, 4):
                nx, ny = x + dx[i], y + dy[i]
                if (0 <= nx < field_x_length) and (0 <= ny < field_y_length):
                    if maze[nx][ny] != '#' and distance[nx][ny] == INF:
                        queue.appendleft((nx, ny))
                        distance[nx][ny] = distance[x][y] + 1
        return distance[gx][gy]
    return bfs()


pairs = []
for i in range(h):
    for j in range(w):
        if maze[i][j] == '.':
            pairs.append([i, j])

MAX = 0
s = set()
for i in range(len(pairs)):
    sx, sy = pairs[i]
    for j in range(len(pairs)):
        gx, gy = pairs[j]
        if i == j or (sx, sy, gx, gy) in s or (gx, gy, sx, sy) in s:
            continue
        s.add((sx, sy, gx, gy))
        s.add((gx, gy, sx, sy))
        r = clear_maze(sx, sy, gx, gy, maze)
        if r == float('infinity'):
            continue
        MAX = max(MAX, r)
print(MAX)