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 io
import os

from collections import Counter, defaultdict, deque
from heapq import heappop, heappush

from itertools import permutations


def solve1(N, A, C):
    best = float("inf")
    for perm in permutations(range(1, N)):
        perm = [0] + list(perm) + [0]
        cost = 0
        for i, j in zip(perm, perm[1:]):
            cost += max(0, A[j] - A[i] - C[i])
        best = min(best, cost)
    return sum(C) + best


def solve2(N, A, C):
    # Find shortest path from smallest to largest A, skipped stuff can be taken in decreasing order for free
    order = sorted(range(N), key=lambda i: A[i])
    source = order[0]
    dest = order[-1]

    def getAdj(i):
        # Didn't know how to optimize this
        for j in range(N):
            yield (j, max(0, A[j] - A[i] - C[i]))

    inf = float("inf")
    dist = [inf] * N
    dist[source] = 0.0
    queue = [(0.0, float(source))]
    while queue:
        d, u = heappop(queue)
        u = int(u)
        if dist[u] == d:
            for v, w in getAdj(u):
                cost = d + w
                if cost < dist[v]:
                    dist[v] = cost
                    heappush(queue, (cost, float(v)))

    return sum(C) + int(dist[dest])


# https://raw.githubusercontent.com/cheran-senthil/PyRival/master/pyrival/data_structures/RangeQuery.py
class RangeQuery:
    def __init__(self, data, func=min):
        self.func = func
        self._data = _data = [list(data)]
        i, n = 1, len(_data[0])
        while 2 * i <= n:
            prev = _data[-1]
            _data.append([func(prev[j], prev[j + i]) for j in range(n - 2 * i + 1)])
            i <<= 1

    def query(self, start, stop):
        """func of data[start, stop)"""
        depth = (stop - start).bit_length() - 1
        return self.func(
            self._data[depth][start], self._data[depth][stop - (1 << depth)]
        )

    def __getitem__(self, idx):
        return self._data[0][idx]


def solve(N, A, C):
    # Editorial solution
    order = sorted(range(N), key=lambda i: A[i])
    rmq = RangeQuery([A[i] + C[i] for i in order], func=max)
    cost = 0
    for i, index in enumerate(order):
        if i != 0:
            cost += max(0, A[index] - rmq.query(0, i))
    return sum(C) + cost


DEBUG = False
if DEBUG:
    import random

    random.seed(0)
    for _ in range(10000):
        N = random.randint(1, 10)
        A = [random.randint(0, 10) for i in range(N)]
        C = [random.randint(0, 10) for i in range(N)]
        print("tc" + str(_), N, A, C)
        ans1 = solve1(N, A, C)
        ans2 = solve2(N, A, C)
        ans = solve(N, A, C)
        print(ans, ans1, ans2)
        assert ans == ans1 == ans2

    exit()

if __name__ == "__main__":
    input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

    TC = 1
    for tc in range(1, TC + 1):
        (N,) = [int(x) for x in input().split()]
        A = []
        C = []
        for i in range(N):
            a, c = [int(x) for x in input().split()]
            A.append(a)
            C.append(c)
        ans = solve(N, A, C)
        print(ans)
