You invited n guests to dinner! You plan to arrange one or more circles of chairs. Each chair is going to be either occupied by one guest, or be empty. You can make any number of circles. 

Your guests happen to be a little bit shy, so the i-th guest wants to have a least l_i free chairs to the left of his chair, and at least r_i free chairs to the right. The "left" and "right" directions are chosen assuming all guests are going to be seated towards the center of the circle. Note that when a guest is the only one in his circle, the l_i chairs to his left and r_i chairs to his right may overlap.

What is smallest total number of chairs you have to use?

Input

First line contains one integer n — number of guests, (1 ⩽ n ⩽ 10^5). 

Next n lines contain n pairs of space-separated integers l_i and r_i (0 ⩽ l_i, r_i ⩽ 10^9).

Output

Output a single integer — the smallest number of chairs you have to use.

Examples

Input

3
1 1
1 1
1 1


Output

6


Input

4
1 2
2 1
3 5
5 3


Output

15


Input

1
5 6


Output

7

Note

In the second sample the only optimal answer is to use two circles: a circle with 5 chairs accomodating guests 1 and 2, and another one with 10 chairs accomodationg guests 3 and 4.

In the third sample, you have only one circle with one person. The guest should have at least five free chairs to his left, and at least six free chairs to his right to the next person, which is in this case the guest herself. So, overall number of chairs should be at least 6+1=7.
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.Random;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.TreeSet;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        int[][][] permutations;
        int cnt;
        int[] p;
        boolean[] used;
        int total;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            if (false) {
                new Tester().go(3);
                return;
            }

            int n = in.readInt();
            Guy[] a = new Guy[n];
            for (int i = 0; i < n; i++) {
                a[i] = new Guy(in.readInt(), in.readInt());
            }
            long answer = new Solve().solve2(a);
            out.print(answer);
        }

        int fact(int n) {
            int f = 1;
            for (int i = 2; i <= n; i++) {
                f *= i;
            }
            return f;
        }

        void gen(int at) {
            if (at == p.length) {
                permutations[p.length][cnt++] = p.clone();
                return;
            }
            for (int i = 0; i < p.length; i++) {
                if (!used[i]) {
                    used[i] = true;
                    p[at] = i;
                    gen(at + 1);
                    used[i] = false;
                }
            }
        }

        void genAll(int maxLen) {
            permutations = new int[maxLen + 1][][];
            for (int i = 1; i <= maxLen; i++) {
                permutations[i] = new int[fact(i)][];
                p = new int[i];
                used = new boolean[i];
                cnt = 0;
                gen(0);
            }
        }

        class Tester {
            void go(int n) {
                Random rnd = new Random(239);
                genAll(n);
                while (true) {
                    Guy[] a = new Guy[n];
                    for (int i = 0; i < a.length; i++) {
                        a[i] = new Guy(rnd.nextInt(10), rnd.nextInt(10));
                    }
                    long sol = new Solve().solve(a);
                    long nai = new Naive(a).solve();
                    if (sol != nai) {
                        System.err.println("FUCK");
                        sol = new Solve().solve(a);
                        nai = new Naive(a).solve();
                    }
                }
            }

        }

        class Solve {
            long solve(Guy[] a) {
                TreeSet<Guy> all =
                        new TreeSet<>(Comparator.<Guy>comparingInt(g -> g.goL - g.goR).thenComparing(g -> g.index));
                all.addAll(Arrays.asList(a));
                while (all.size() > 1) {
                    Guy g0 = all.first();
                    Guy g1 = all.last();
                    Guy g = g0.merge(g1);
                    if (g0.getRes() + g1.getRes() <= g.getRes()) {
                        break;
                    }
                    all.remove(g0);
                    all.remove(g1);
                    all.add(g);
                }
                long total = 0;
                for (Guy g : all) {
                    total += g.getRes();
                }
                return total;
            }

            long solve2(Guy[] a) {
                int n = a.length;
                long answer = n;
                long[] ls = new long[n];
                long[] rs = new long[n];
                for (int i = 0; i < n; i++) {
                    ls[i] = a[i].goL;
                    rs[i] = a[i].goR;
                }
                Arrays.sort(ls);
                Arrays.sort(rs);
                for (int i = 0; i < n; i++) {
                    answer += Math.max(ls[i], rs[i]);
                }
                return answer;
            }

        }

        class Naive {
            Guy[] a;

            public Naive(Guy[] a) {
                this.a = a;
            }

            long solve() {
                int n = a.length;
                if (n == 0) {
                    return 0;
                }

                long minAns = Long.MAX_VALUE;
                for (int m = 1; m < 1 << n; m++) {
                    int sz0 = 0;
                    int sz1 = 0;
                    for (int i = 0; i < n; i++) {
                        if (((m >> i) & 1) == 1) {
                            sz0++;
                        } else {
                            sz1++;
                        }
                    }
                    int[][] indexes = new int[2][];
                    indexes[0] = new int[sz0];
                    indexes[1] = new int[sz1];
                    Guy[] g1 = new Guy[sz1];
                    sz0 = sz1 = 0;
                    for (int i = 0; i < n; i++) {
                        if (((m >> i) & 1) == 1) {
                            indexes[0][sz0++] = i;
                        } else {
                            indexes[1][sz1] = i;
                            g1[sz1] = a[i];
                            sz1++;
                        }
                    }
                    for (int[] perm : permutations[sz0]) {
                        Guy g0 = a[indexes[0][perm[0]]];
                        for (int i = 1; i < indexes[0].length; i++) {
                            g0 = g0.merge(a[indexes[0][perm[i]]]);
                        }
                        minAns = Math.min(minAns, g0.getRes() + new Naive(g1).solve());
                    }
                }

                return minAns;
            }

        }

        class Guy {
            int index = total++;
            long width;
            int goL;
            int goR;

            Guy(int l, int r) {
                width = 1;
                goL = l;
                goR = r;
            }

            Guy(long width, int goL, int goR) {
                this.width = width;
                this.goL = goL;
                this.goR = goR;
            }

            long getRes() {
                return width + Math.max(goL, goR);
            }

            Guy merge(Guy with) {
                int between = Math.max(goR, with.goL);
                return new Guy(width + with.width + between, goL, with.goR);
            }

            public String toString() {
                return "Guy{" +
                        "index=" + index +
                        ", width=" + width +
                        ", goL=" + goL +
                        ", goR=" + goR +
                        '}';
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void print(long i) {
            writer.print(i);
        }

    }
}

