import java.io.*;
import java.util.*;

public class pulp_as implements Runnable {
    class Book {
        int i;
        long r;
        long p;

        Book(int i, long r, long p) {
            this.i = i;
            this.r = r;
            this.p = p;
        }
    }

    BufferedReader in;
    StringTokenizer st;

    public int nextInt() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return Integer.parseInt(st.nextToken());
    }

    public void solve() throws IOException {
        in = new BufferedReader(new FileReader("pulp.in"));
        PrintWriter out = new PrintWriter(new File("pulp.out"));

        int n = nextInt();
        Book[] b = new Book[n];
        for (int i = 0; i < n; i++) {
            b[i] = new Book(i, nextInt(), nextInt());
        }

        Arrays.sort(b, new Comparator<Book>() {
            public int compare(Book o1, Book o2) {
                return o1.r < o2.r ? -1 : o1.r > o2.r ? 1 : o1.i - o2.i;
            }
        });

        TreeSet<Book> events = new TreeSet<Book>(new Comparator<Book>() {
            public int compare(Book o1, Book o2) {
                return o1.p < o2.p ? -1 : o1.p > o2.p ? 1 : o1.i - o2.i;
            }
        });

        long now = b[0].r;
        long ans = 0;
        int cur = 0;
        while (cur < n || events.size() > 0) {
            if (cur < n) {
                int last = cur;
                events.add(b[cur++]);
                while (cur < n && b[cur].r == b[last].r) {
                    events.add(b[cur++]);
                }
                now = b[last].r;
            }
            while (events.size() > 0) {
                Book e = events.first();
                events.remove(e);
                if (cur < n && e.p > b[cur].r - now) {
                    long delta = b[cur].r - now;
                    now = b[cur].r;
                    e.p = e.p - delta;
                    events.add(e);
                    break;
                } else {
                    now += e.p;
                    ans += now;
//                    System.out.println(e.i + " " + now);
                }
            }
        }

        out.println(ans);

        in.close();
        out.close();
    }

    public void run() {
        try {
            solve();
        } catch (IOException e) {
            System.exit(64);
        }
    }

    public static void main(String[] arg) throws IOException {
        new Thread(new pulp_as()).start();
    }
}
