h, w = list(map(int, input().split()))
s = []
for i in range(h):
    s.append(input().strip())

# start, goal の候補
reps = []
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            reps.append([i, j])
ans = 0
for k in range(len(reps) - 1):
    for l in range((k + 1), len(reps), 1):
        # unvisited: -1, visited: 0, goal: 1
        start = reps[k]
        goal = reps[l]
        visits = [[-1 for i in range(w)] for j in range(h)]
        visits[goal[0]][goal[1]] = 1
        queue = [reps[k]]
        depth = 0

        while 0 < len(queue):
            # 1. まず、ゴールに到着しているか確認する
            # 2-1. していれば、その start, goal の組における最短経路が計算できたので、depths に追加する
            # 2-2. していなければ、自分のいるマスを訪問済みにし、次に進む道の候補を挙げて、それらを queue に突っ込む
            now = queue.pop(0)

            if visits[now[0]][now[1]] == 1:
                break
            else:
                visits[now[0]][now[1]] = 0
            if (now[0] <= (h - 2)):
                if (s[now[0] + 1][now[1]] == ".") and (visits[now[0] + 1][now[1]] != 0):
                    queue.append([(now[0] + 1), now[1]])
            if (now[1] <= (w - 2)):
                if (s[now[0]][now[1] + 1] == ".") and (visits[now[0]][now[1] + 1] != 0):
                    queue.append([now[0], (now[1] + 1)])
            if (1 <= now[0]):
                if (s[now[0] - 1][now[1]] == ".") and (visits[now[0] - 1][now[1]] != 0):
                    queue.append([(now[0] - 1), now[1]])
            if (1 <= now[1]):
                if (s[now[0]][now[1] - 1] == ".") and (visits[now[0]][now[1] - 1] != 0):
                    queue.append([now[0], (now[1] - 1)])
            depth += 1
        if ans <= depth:
            ans = depth
print(ans)
