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.
// Main Code at the Bottom
import java.util.*;
import java.io.*; 
public class Main{
	//Fast IO class
    static class FastReader {
        BufferedReader br; 
        StringTokenizer st; 
        public FastReader() {
        	boolean env=System.getProperty("ONLINE_JUDGE") != null;
        	//env=true;
        	if(!env) {
        		try {
					br=new BufferedReader(new FileReader("src\\input.txt"));
				} catch (FileNotFoundException e) {
					e.printStackTrace();
				}
        	}
        	else 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; 
        } 
    }     
    static long MOD=(long)1e9+7;
    //debug
    static void debug(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
    static FastReader sc=new FastReader();
    static PrintWriter out=new PrintWriter(System.out);  
    //Global variables and functions
    // Pair
    static class pair{
    	long x,y;
    	pair(long a,long b){
    		this.x=a;
    		this.y=b;
    	}
    	public boolean equals(Object obj) {
    		if(obj == null || obj.getClass()!= this.getClass()) return false;
            pair p = (pair) obj;
            return (this.x==p.x && this.y==p.y);
        }
    	public int hashCode() {
            return Objects.hash(x,y);
        }
    }
    //Main function(The main code starts from here)
    public static void main (String[] args) throws java.lang.Exception {
    	int test=1;
    	//test=sc.nextInt();
    	while(test-->0) {
    		int n=sc.nextInt();
    		pair a[] = new pair[n];
    		long ans = 0;
    		for(int i=0;i<n;i++) a[i]=new pair(sc.nextLong(),sc.nextLong());
    		Arrays.parallelSort(a,(p1,p2)->Long.compare(p1.x, p2.x));
    		pair graph[] = new pair[n];
    		for(int i = 0; i < n; i++) {
    			int l = i+1, r = n-1, idx = -1;
    			while(l <= r) {
    				int mid = l+(r-l)/2;
    				if(a[mid].x - (a[i].x + a[i].y) <= 0) {
    					idx = mid;
    					l = mid+1;
    				}
    				else r = mid-1;
    			}
    			if(idx == -1) graph[i] = new pair(i+1, n);
    			else graph[i] = new pair(idx, idx+1);
    			ans += a[i].y;
    		}
    		PriorityQueue<pair> q = new PriorityQueue<>((p1,p2)->Long.compare(p1.y, p2.y));
    		q.add(new pair(0,0));
    		long dist[]=new long[n];
    		Arrays.fill(dist, Long.MAX_VALUE/100);
    		dist[0]=0;
    		while(!q.isEmpty()) {
    			pair p = q.poll();
    			int s = (int)p.x;
    			long d = p.y;
    			if(dist[s] != d) continue;
    			dist[s] = d;
    			if(s == n-1) break;
    			int v1 = (int)graph[s].x, v2 = (int)graph[s].y, v3 = s-1;
    			if(v1 < n) {
    				long d1 = d + Math.max(0, a[v1].x - (a[s].x + a[s].y));
    				if(d1 < dist[v1]) {
    					q.add(new pair(v1, d1));
    					dist[v1] = d1;
    				}
    			}
    			if(v2 < n) {
    				long d2 = d+Math.max(0, a[v2].x - (a[s].x + a[s].y));
    				if(d2 < dist[v2]) {
    					q.add(new pair(v2, d2));
    					dist[v2] = d2;
    				}
    			}	
    			if(v3 >= 0 && v3 < n) {
    				long d3 = d;
    				if(d3 < dist[v3]) {
    					q.add(new pair(v3, d3));
    					dist[v3] = d3;
    				}
    			}
    		}
    		ans+=dist[n-1];
    		out.println(ans);
    	}
        out.flush();
        out.close();
    }
}