import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); PriorityQueue queue = new PriorityQueue<>(); long total = 0; int first = sc.nextInt(); total += first; queue.add(new Path(0, n, first)); sc.nextInt(); for (int i = 1; i < n; i++) { int each = sc.nextInt(); total += each; queue.add(new Path(i, n, each)); queue.add(new Path(i - 1, i, sc.nextInt())); } UnionFindTree uft = new UnionFindTree(n + 1); while (queue.size() > 0) { Path p = queue.poll(); if (!uft.same(p)) { uft.unite(p); total += p.cost; } } 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 (x == parents[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 cost; public Path(int left, int right, int cost) { this.left = left; this.right = right; this.cost = cost; } public int compareTo(Path another) { return cost - another.cost; } } }