You still have partial information about the score during the historic football match. You are given a set of pairs (a_i, b_i), indicating that at some point during the match the score was "a_i: b_i". It is known that if the current score is «x:y», then after the goal it will change to "x+1:y" or "x:y+1". What is the largest number of times a draw could appear on the scoreboard?

The pairs "a_i:b_i" are given in chronological order (time increases), but you are given score only for some moments of time. The last pair corresponds to the end of the match.

Input

The first line contains a single integer n (1 ≤ n ≤ 10000) — the number of known moments in the match.

Each of the next n lines contains integers a_i and b_i (0 ≤ a_i, b_i ≤ 10^9), denoting the score of the match at that moment (that is, the number of goals by the first team and the number of goals by the second team).

All moments are given in chronological order, that is, sequences x_i and y_j are non-decreasing. The last score denotes the final result of the match.

Output

Print the maximum number of moments of time, during which the score was a draw. The starting moment of the match (with a score 0:0) is also counted.

Examples

Input

3
2 0
3 1
3 4


Output

2


Input

3
0 0
0 0
0 0


Output

1


Input

1
5 4


Output

5

Note

In the example one of the possible score sequences leading to the maximum number of draws is as follows: 0:0, 1:0, 2:0, 2:1, 3:1, 3:2, 3:3, 3:4.


//
//import javax.print.DocFlavor;
//import javax.swing.*;
//import javax.swing.text.StyleContext;
//import java.awt.image.AreaAveragingScaleFilter;
import javax.print.attribute.Attribute;
import javax.print.attribute.HashAttributeSet;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.nio.channels.AcceptPendingException;
import java.nio.charset.IllegalCharsetNameException;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Collections;
import java.io.InputStreamReader;
import java.util.logging.SimpleFormatter;


public   class Main{

    static long counter(long x1 , long y1 , long x2 , long y2){
        if (x1 > y2 || x2 < y1)
            return 0 ;


        long ret = Math.min(x2 , y2) - Math.max(x1 , y1)  ;
        if (x1 != y1) ret++ ;

        return Math.abs(ret)  ;

    }


    



    public static void main(String[] args) {

        try {
            PrintWriter fop = new PrintWriter(System.out);
             FastScanner fsca = new FastScanner();

            int t = fsca.nextInt();
            long ct = 0 ;
            long x1 = 0 ;
            long y1 = 0 ;
            while (t-- > 0){
                long x2 = fsca.nextLong();
                long y2 = fsca.nextLong();
                ct += counter(x1 , y1 , x2 , y2) ;
                x1 = x2 ; y1 = y2 ;
            }
            fop.println(ct + 1 );


























//        int tree[] = new int[4*n+1] ;
//        BuiltTree(A , 0 , n-1 , tree , 1);
//        int lazy[] = new int[4*n + 1] ;
//
//        updateRangeLazy(tree , lazy , 0 , n-1 , 0 , 2 , 10 , 1);
//        updateRangeLazy(tree , lazy , 0 , n-1 , 0 , 4 , 10 , 1);
//
//        fop.println(querylazy(tree , lazy , 0 , n-1 , 1 ,1 ,1));
//
//        updateRangeLazy(tree, lazy , 0 , n-1 , 10 , 4 , 3 ,1);
//        fop.println(querylazy(tree , lazy , 0 , n-1 , 3 , 5 , 1 ));


            fop.flush();
            fop.close();

        }
        catch (Exception e){
            return;
        }



    }
    /*-----------------------------------------------------------------------------------------------------------------------------------------------*/

    // segment tree


    //  BuiltTree(A , 0 , n-1 , tree , 1);
    static void BuiltTree(int A[] , int s , int e , int tree[] , int index){
        if (s== e) {
            tree[index] = A[s] ;
            return;
        }

        int mid = (s+e)/2;
        BuiltTree(A , s , mid , tree , 2*index);
        BuiltTree(A , mid+1 , e , tree , 2*index+1);
        tree[index] = Math.min( tree[2*index], tree[2*index+1] ) ;
        return;

    }

    static int query(int tree[] , int ss , int se , int qs , int qe , int index){

        // complete overlap
        if (ss >= qs && se <= qe)
            return  tree[index];

        //no overlap
        if (qe < ss || qs > se)
            return Integer.MAX_VALUE ;

        // partial overlap
        int mid = (ss+se)/2 ;
        int left = query(tree , ss , mid , qs, qe , 2*index) ;
        int right = query(tree , mid+1 , se , qs, qe , 2*index+1) ;
        return Math.min(left , right) ;
    }


   static void update(int tree[] , int ss , int se , int i , int increment , int index){
        // i is the index of which we want to update the value

        if (i > se || i<ss)
            return;

        if (ss == se){
              tree[index] += increment ;
            return;
        }
        int mid = (ss+se)/2 ;
        update(tree , ss , mid , i , increment , 2*index);
        update(tree , mid+1 , se , i , increment , 2*index+1);
        tree[index]  = Math.min(tree[2*index], tree[2*index+1] ) ;

    }

    static  void updateRange(int tree[] , int ss , int se , int l , int r , int inc , int index){

        if (l > se || r< ss)
            return;

        if (ss == se){
            tree[index] += inc ;
             return;
        }

        int mid = (ss+se)/2 ;
        updateRange(tree , ss , mid , l , r , inc , 2*index);
        updateRange(tree , mid+1 , se , l , r , inc , 2*index + 1);

        tree[index] = Math.min( tree[2*index], tree[2*index + 1] ) ;
        return;


    }
    // Lazy rnage Update

    static void updateRangeLazy(int tree[] , int lazy[] , int ss ,int se , int l , int r , int increment , int index){

        if (lazy[index] != 0 ){
            tree[index] += lazy[index];

            if (ss != se){
                lazy[2*index]  +=  lazy[index];
                lazy[2*index + 1]  +=  lazy[index];
            }
            lazy[index ] = 0 ;
        }

        if (ss > r && se< l )
            return;

        if (ss >= l && se <= r) {
            tree[index] += increment;


            if (ss != se) {
                lazy[2 * index] += increment;
                lazy[2 * index + 1] += increment;
            }
            return;
        }

        int mid = (ss + se)/2 ;
        updateRange(tree , ss , mid , l , r , increment , 2*index);
        updateRange(tree , mid + 1 , se , l , r , increment , 2*index + 1);

        tree[index] =  Math.min( tree[2*index], tree[2*index + 1] ) ;

    }

    // min lazy query

    static int querylazy(int tree[] , int lazy[] , int ss , int se , int qs , int qe , int index) {

        if (lazy[index] != 0) {

            tree[index] += lazy[index];
            if (ss != se) {
                lazy[2 * index] += lazy[index];
                lazy[2 * index + 1] += lazy[index];
            }
            lazy[index] = 0;
        }

        if (ss > qe || se < qs)
            return Integer.MAX_VALUE;

        if (ss >= qs && se <= qe)
            return tree[index];

        int mid = (ss + se) / 2;
        int left = querylazy(tree, lazy, ss, mid, qs, qe, 2 * index);
        int right = querylazy(tree, lazy, mid + 1, se, qs, qe, 2 * index + 1);

        return Math.min(left, right);

    }





/*-----------------------------------------------------------------------------------------------------------------------------------------------------------*/
    static boolean isEven(int a){
        if (a%2 == 0)
            return true ;
        else return false ;
    }
    static boolean isEvenLong(long a){
        if (a%2 == 0)
            return true ;
        else return false ;
    }

    static void sieve(int n){
        boolean[] flag = new boolean[n] ;

        for (int i=2 ; i*i<n ; i++){
            if (flag[i])
                continue;
            else
                for (int j= i*i ; j<=n ; j+= i){
                    flag[j] = true;
                }
        }


    }
    static int gcd(int a , int b){
        if (b > a){
            int tenp = b ;
            b = a ;
            a = tenp ;
        }
        int temp = 0 ;
        while (b != 0){
            a %= b ;
            temp = b ;
            b = a ;
            a = temp ;
        }
        return a ;
    }

    static long gcd1( long a , long b){
        if (b > a){
            long tenp = b ;
            b = a ;
            a = tenp ;
        }
        long temp = 0 ;
        while (b != 0){
            a %= b ;
            temp = b ;
            b = a ;
            a = temp ;
        }
        return a ;
    }






    static final Random random=new Random();

    static void ruffleSort(int[] a) {
        int n=a.length;//shuffle, then sort
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n), temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        Arrays.sort(a);
    }




    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long[] readLongArray(int n){
            long[] a = new long[n];
            for (int i=0 ; i<n ; i++)
                a[i] = nextLong() ;
            return a ;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }






}


