use std::cmp::max; fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let mut a: Vec = vec![]; let mut p: Vec = vec![]; for _ in 0..n { let mut pa = String::new(); std::io::stdin().read_line(&mut pa).ok(); let pa: Vec = pa.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); p.push(pa[0]); a.push(pa[1]); } let mut dp: Vec> = vec![vec![0; n]; 2]; dp[0][n-1] = a[n-1]; dp[1][n-1] = p[n-1]; for i in (1..n).rev() { dp[0][i-1] = max(dp[0][i] + a[i], dp[1][i] + p[i]) + a[i-1]; dp[1][i-1] = max(dp[0][i], dp[1][i]) + p[i-1]; } println!("{}", max(dp[0][0], dp[1][0])); }