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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

/*
11
0 1
2 1
2 3
3 1
3 0
4 2
10 6
12 2
13 1
14 1
20 2
=====
19+1+4+4
=====

 */

public class SolutionC extends Thread {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                                            InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    private static final FastReader scanner = new FastReader();

    public static void main(String[] args) {
        solve();
    }

    static class City implements Comparable<City>{
        long a;
        long c;

        public City(int a, int c) {
            this.a = a;
            this.c = c;
        }

        @Override
        public int compareTo(City o) {
            return Long.compare(a, o.a);
        }
    }

    private static void solve() {
        int n = scanner.nextInt();
        City[] cities = new City[n];
        long cost = 0;
        for (int i = 0; i < n; i++) {
            int ai = scanner.nextInt();
            int ci = scanner.nextInt();
            cities[i] = new City(ai, ci);
            cost += ci;
        }

        Arrays.sort(cities);

        int[] prefixMax = new int[n];

        long max = cities[0].a + cities[0].c;
        for (int i = 1; i < n; i++) {
            long tmp = cities[i].a + cities[i].c;

            if (tmp >= max) {
                prefixMax[i] = i;
                max = tmp;
            } else {
                prefixMax[i] = prefixMax[i-1];
            }
        }

        int pointer = 0;
        while(pointer != n-1) {
            int index = prefixMax[pointer];
            long toFree = cities[index].a + cities[index].c;

            int low = pointer;
            int high = n;
            while (high - low > 1) {
                int mid = (low + high) / 2;

                if (cities[mid].a > toFree) {
                    high = mid;
                } else {
                    low = mid;
                }
            }

            if (low == pointer) {
                cost += cities[pointer+1].a - toFree;
                pointer++;
            } else {
                pointer = low;
            }
        }

        System.out.println(cost);
    }

    //REMINDERS:
    //- CHECK FOR INTEGER-OVERFLOW BEFORE SUBMITTING

    //- CAN U BRUTEFORCE OVER SOMETHING, TO MAKE IT EASIER TO CALCULATE THE SOLUTION
}