import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Scanner; /** * Built using CHelper plug-in * Actual solution is at the top * * @author silviase */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); tenhomu solver = new tenhomu(); solver.solve(1, in, out); out.close(); } static class tenhomu { public void solve(int testNumber, Scanner in, PrintWriter out) { int n = in.nextInt(); long[] accEven = new long[n + 1]; long[] accOdd = new long[n + 1]; long max = -1; long cmp = 0; for (int i = 1; i <= n; i++) { accEven[i] = in.nextInt(); accOdd[i] = in.nextInt(); cmp += accOdd[i] - accEven[i]; } for (int i = 0; i <= n; i++) { max = Math.max(max, cmp = cmp + (accEven[i] - accOdd[i]) * 2); } out.println(max); } } }