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.
//#include <bits/stdc++.h>
//#include <ext/pb_ds/hash_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/rope>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <random>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <ctime>

#define X first
#define Y second
#define ls rt<<1
#define rs rt<<1|1
#define getmid ((l+r)>>1)
#define PB push_back
#define EB emplace_back
#define lowbit(x) ((x)&-(x))
#define sz(a) ((int)a.size())
#define ALL(x) x.begin(),x.end()
#define mst(x,a) memset(x, a, sizeof(x))
using namespace std;
#ifdef LOCAL
#define dbg(args...) cout << #args << " -> ", err(args);
void err(){ cout << endl; }
template<typename T, typename... Args>
void err(T a, Args... args){ cout << a << ' '; err(args...); }
#else
#define dbg(args...)
#endif // LOCAL

//using namespace __gnu_cxx;
//using namespace __gnu_pbds;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;

const int N = 1e5 + 10;
const int M = 200 + 10;
const int maxn = 1e6 + 10;
const int mod = 1000010029;
const db eps = 1e-15;
const db pi = acos(-1.0);
const ll base = 65537;

struct Node {
    int a,c,id;
    bool operator < (const Node& A) const {
        if(a ^ A.a) return a < A.a;
        return c > A.c;
    }
} p[N];

int n;

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif //LOCAL
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    ll ans = 0;
    for(int i=1; i<=n; i++) {
        int a,c; cin>>a>>c;
        p[i] = {a, c, i};
        ans += c;
    }
    sort(p+1, p+1+n);
    int pos = p[1].a + p[1].c;
    for(int i=2; i<=n; i++) {
        if(pos < p[i].a) ans += p[i].a - pos;
        pos = max(pos, p[i].a + p[i].c);
    }
    cout<<ans<<'\n';

    return 0;
}
