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

def init_start(maze):
    for j in range(len(maze)):
        for i in range(len(maze[0])):
            if maze[j][i] == ".":
                sx = i
                sy = j
    return sx, sy

def calc_distance(maze):
    global maxd
    global sx, sy
    global nextx, nexty
    # Goalまでの距離としてはあり得ない数値を設定
    INF = 100000000

    field_x_length = len(maze[0])
    field_y_length = len(maze)

    distance = []
    for i in range(field_y_length):
        distance.append([])
        for j in range(field_x_length):
            distance[i].append(INF)

    queue = []

    queue.insert(0, (sy, sx))

    distance[sy][sx] = 0

    # Goalにつくまで以下ループ
    while True:
        # 最初に入れた要素を取り出す
        y, x = queue.pop()

        # 新しい座標(ny, nx)に現時点の座標から
        # (0, 1)(1, 0)(0, -1)(-1, 0)移動した値を代入  
        for i in range(0, 4):
            nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]


            if (0 <= nx and nx < field_x_length and 0 <= ny and ny < field_y_length and maze[ny][nx] != '#' and distance[ny][nx] == INF):
                queue.insert(0, (ny, nx))
                distance[ny][nx] = distance[y][x] + 1
                if maxd < distance[y][x] + 1:
                    maxd = distance[y][x] + 1
                    nexty = ny
                    nextx = nx
        if len(queue) == 0: break

maxd = 0
sx, sy = init_start(maze)
distance = calc_distance(maze)
sx, sy = nextx, nexty
distance = calc_distance(maze)
sx, sy = nextx, nexty
distance = calc_distance(maze)
print(maxd)
