def main():
    N = 1

    while N != 0:
        N = int(input())
        if N == 0:
            break

        v = list(map(int, input().split()))
        dp = [[0, 0] for _ in range(N)]

        for i in range(N - 1):
            dp[i][0] = max(v[i], v[i + 1])

        turn = 0
        past_turn = 1

        for interval_size in range(4, N + 1, 2):
            past_turn, turn = turn, 1 - turn

            for i, j in zip(range(N - interval_size + 1), range(interval_size - 1, N)):
                dp[i][turn] = max(
                    v[i] + min(dp[i + 1][past_turn], dp[i + 2][past_turn]),
                    v[j] + min(dp[i][past_turn], dp[i + 1][past_turn])
                )

        print(dp[0][turn])

if __name__ == "__main__":
    main()