import java.util.Scanner;

public class Cartoes {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = 1;

        while (N != 0) {
            N = scanner.nextInt();
            if (N == 0) {
                break;
            }

            int[] v = new int[N];

            for (int i = 0; i < N; ++i) {
                v[i] = scanner.nextInt();
            }

            long[][] dp = new long[N][2];

            for (int i = 0; i < N - 1; ++i) {
                dp[i][0] = Math.max(v[i], v[i + 1]);
            }

            int turn = 0;
            int pastTurn = 1;

            for (int intervalSize = 4; intervalSize <= N; intervalSize += 2) {
                pastTurn = turn;
                turn = (turn == 0) ? 1 : 0;

                for (int i = 0, j = intervalSize - 1; j < N; ++i, ++j) {
                    dp[i][turn] = Math.max(v[i] + Math.min(dp[i + 1][pastTurn], dp[i + 2][pastTurn]),
                            v[j] + Math.min(dp[i][pastTurn], dp[i + 1][pastTurn]));
                }
            }

            System.out.println(dp[0][turn]);
        }

        scanner.close();
    }
}