#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let xs: Vec<i64> = sc.vec(n);

    if n == 2 {
        put!(*max!(..xs).unwrap());
        return;
    }
    if n == 3 {
        put!(*max!(..xs).unwrap());
        return;
    }
    if n == 4 {
        put!(max!(
                xs[0] + xs[2],
                xs[0] + xs[3],
                xs[1] + xs[3]
        ));
        return;
    }

    let mut dp: Vec<i64> = vec![0; n];
    let mut dp_sup: Vec<i64> = vec![0; n];

    dp[n-1] = 0;
    dp[n - 2] = max!(xs[n-1], xs[n-2]);
    dp[n - 3] = max!(xs[n-1], xs[n-2], xs[n-3]);

    dp_sup[n - 1] = xs[n - 1];
    dp_sup[n - 2] = max!(xs[n-1], xs[n-2]);
    dp_sup[n - 3] = xs[n-3] + xs[n - 1];

    for i in (0..n - 3).rev() {
        if (n - i) % 2 == 0 {  // 残り偶数
            dp[i] = max!(
                xs[i] + dp[i + 2],
                xs[i + 1] + dp_sup[i + 3]
            );
            dp_sup[i] = dp[i];
        } else {
            dp[i] = max!(
                xs[i] + dp[i + 2],
                xs[i + 1] + dp[i + 3],
                dp_sup[i + 2]
            );
            dp_sup[i] = xs[i] + dp_sup[i + 2];
        }
    }

    // trace!(&dp);
    // trace!(&dp_sup);
    put!(dp[0]);

}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 15108