import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] prices = new int[n]; int[] costs = new int[n]; UnionFindTree uft = new UnionFindTree(n + 1); PriorityQueue queue = new PriorityQueue<>(); long total = 0; for (int i = 0; i < n; i++) { int p = sc.nextInt(); total += p; queue.add(new Path(i, n, p)); int c = sc.nextInt(); if (i > 0) { queue.add(new Path(i - 1, i, c)); } } while (queue.size() > 0) { Path p = queue.poll(); if (!uft.same(p)) { uft.unite(p); total += p.value; } } System.out.println(total); } static class UnionFindTree { int[] parents; public UnionFindTree(int size) { parents = new int[size]; for (int i = 0; i < size; i++) { parents[i] = i; } } public int find(int x) { if (parents[x] == x) { return x; } else { return parents[x] = find(parents[x]); } } public boolean same(int x, int y) { return find(x) == find(y); } public boolean same(Path p) { return same(p.left, p.right); } public void unite(int x, int y) { if (!same(x, y)) { parents[find(x)] = find(y); } } public void unite(Path p) { unite(p.left, p.right); } } static class Path implements Comparable { int left; int right; int value; public Path(int left, int right, int value) { this.left = left; this.right = right; this.value = value; } public int compareTo(Path another) { return value - another.value; } } }