import java.util.*; public class Main { static int[][] dp; static int[] pins; static int[] scores; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); pins = new int[n]; scores = new int[n]; for (int i = 0; i < n; i++) { pins[i] = sc.nextInt(); scores[i] = sc.nextInt(); } dp = new int[2][n]; System.out.println(dfw(n - 1, 0)); } static int dfw(int idx, int type) { if (idx < 0) { if (type == 1) { return Integer.MIN_VALUE; } else { return 0; } } if (dp[type][idx] == 0) { if (type == 0) { dp[type][idx] = Math.max(pins[idx] * 2 + dfw(idx - 1, 1), pins[idx] + dfw(idx - 1, 0)); } else { dp[type][idx] = Math.max(scores[idx] * 2 + dfw(idx - 1, 1), scores[idx] + dfw(idx - 1, 0)); } } return dp[type][idx]; } }