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

reps = []
for i in range(h + 2):
    for j in range(w + 2):
        if s[i][j] == ".":
            reps.append([i, j])
depths = []
for k in range(len(reps)):
    for l in range(k, len(reps), 1):
        start = reps[k]
        goal = reps[l]
        visits = [[-1 for i in range(w + 2)] for j in range(h + 2)]
        visits[goal[0]][goal[1]] = 1
        queue = [reps[k]]
        depth = 0

        while True:
            clear = False
            tmp_queue = []
            for now in queue:
                if visits[now[0]][now[1]] == 1:
                    clear = True
                    break
                else:
                    visits[now[0]][now[1]] = 0
                if (s[now[0] + 1][now[1]] == ".") and (visits[now[0] + 1][now[1]] != 0):
                    tmp_queue.append([(now[0] + 1), now[1]])
                if (s[now[0]][now[1] + 1] == ".") and (visits[now[0]][now[1] + 1] != 0):
                    tmp_queue.append([now[0], (now[1] + 1)])
                if (s[now[0] - 1][now[1]] == ".") and (visits[now[0] - 1][now[1]] != 0):
                    tmp_queue.append([(now[0] - 1), now[1]])
                if (s[now[0]][now[1] - 1] == ".") and (visits[now[0]][now[1] - 1] != 0):
                    tmp_queue.append([now[0], (now[1] - 1)])
            if clear:
                break
            else:
                depth += 1
                queue = tmp_queue
        depths.append(depth)
print(max(depths))
