There are n cities numbered from 1 to n, and city i has beauty a_i.

A salesman wants to start at city 1, visit every city exactly once, and return to city 1.

For all i≠ j, a flight from city i to city j costs max(c_i,a_j-a_i) dollars, where c_i is the price floor enforced by city i. Note that there is no absolute value. Find the minimum total cost for the salesman to complete his trip.

Input

The first line contains a single integer n (2≤ n≤ 10^5) — the number of cities.

The i-th of the next n lines contains two integers a_i, c_i (0≤ a_i,c_i≤ 10^9) — the beauty and price floor of the i-th city.

Output

Output a single integer — the minimum total cost.

Examples

Input


3
1 9
2 1
4 1


Output


11


Input


6
4 2
8 4
3 0
2 3
7 1
0 1


Output


13

Note

In the first test case, we can travel in order 1→ 3→ 2→ 1. 

  * The flight 1→ 3 costs max(c_1,a_3-a_1)=max(9,4-1)=9. 
  * The flight 3→ 2 costs max(c_3, a_2-a_3)=max(1,2-4)=1. 
  * The flight 2→ 1 costs max(c_2,a_1-a_2)=max(1,1-2)=1. 



The total cost is 11, and we cannot do better.
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class C implements Runnable {

    public void run() {
        long startTime = System.nanoTime();

        int n = nextInt();
        long[] a = new long[n];
        int[] c = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextLong() << 32 | i;
            c[i] = nextInt();
        }
        Arrays.sort(a);

        int[] f = new int[n];
        for (int i = 0; i < n; i++) {

            int maxGap = c[(int) a[i]];

            int min = i, max = n;
            while (max - min > 1) {
                int mid = min + max >> 1;
                long d = (a[mid] >> 32) - (a[i] >> 32);
                if (d <= maxGap) {
                    min = mid;
                } else {
                    max = mid;
                }
            }

            f[i] = min;

        }

        long ret = 0;
        for (int x : c) {
            ret += x;
        }

//        int start = 0;
//        while ((int) a[start] != 0) {
//            start++;
//        }

        int cur = 0;
        while (cur != n - 1) {

            int max = f[cur];
            for (int i = cur; i <= max; i++) {
                max = Math.max(max, f[i]);
            }

            if (max == n - 1) {
                break;
            }

            long d = (long) 1e18;
            for (int i = cur; i <= max; i++) {
                long t = (a[max + 1] >> 32) - (a[i] >> 32) - c[(int) a[i]];
                d = Math.min(d, t);
            }
            cur = max + 1;
            ret += d;

        }

        println(ret);

        if (fileIOMode) {
            System.out.println((System.nanoTime() - startTime) / 1e9);
        }
        out.close();
    }

    //-----------------------------------------------------------------------------------

    private static boolean fileIOMode;
    private static BufferedReader in;
    private static PrintWriter out;
    private static StringTokenizer tokenizer;

    public static void main(String[] args) throws Exception {
        fileIOMode = args.length > 0 && args[0].equals("!");
        if (fileIOMode) {
            in = new BufferedReader(new FileReader("a.in"));
            out = new PrintWriter("a.out");
        } else {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
        tokenizer = new StringTokenizer("");

        new Thread(new C()).start();
    }

    private static String nextLine() {
        try {
            return in.readLine();
        } catch (IOException e) {
            return null;
        }
    }

    private static String nextToken() {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(nextLine());
        }
        return tokenizer.nextToken();
    }

    private static int nextInt() {
        return Integer.parseInt(nextToken());
    }

    private static long nextLong() {
        return Long.parseLong(nextToken());
    }

    private static double nextDouble() {
        return Double.parseDouble(nextToken());
    }

    private static BigInteger nextBigInteger() {
        return new BigInteger(nextToken());
    }

    private static void print(Object o) {
        if (fileIOMode) {
            System.out.print(o);
        }
        out.print(o);
    }

    private static void println(Object o) {
        if (fileIOMode) {
            System.out.println(o);
        }
        out.println(o);
    }

    private static void printf(String s, Object... o) {
        if (fileIOMode) {
            System.out.printf(s, o);
        }
        out.printf(s, o);
    }
}
