There is an infinite sequence consisting of all positive integers in the increasing order: p = {1, 2, 3, ...}. We performed n swap operations with this sequence. A swap(a, b) is an operation of swapping the elements of the sequence on positions a and b. Your task is to find the number of inversions in the resulting sequence, i.e. the number of such index pairs (i, j), that i < j and pi > pj.

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of swap operations applied to the sequence.

Each of the next n lines contains two integers ai and bi (1 ≤ ai, bi ≤ 109, ai ≠ bi) — the arguments of the swap operation.

Output

Print a single integer — the number of inversions in the resulting sequence.

Examples

Input

2
4 2
1 4


Output

4


Input

3
1 6
3 4
2 5


Output

15

Note

In the first sample the sequence is being modified as follows: <image>. It has 4 inversions formed by index pairs (1, 4), (2, 3), (2, 4) and (3, 4).
import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class Main
{
    static long mod=1000000007,ans=0;
    public static void main(String[] args) throws Exception
    {
    	FastReader in=new FastReader();
    	PrintWriter pw=new PrintWriter(System.out);
    	int n=in.nextInt();
    	TreeMap<Integer,Integer> tm=new TreeMap<>();
    	while(n-->0)
    	{
    		int a=in.nextInt();
    		int b=in.nextInt();
    		int c=tm.getOrDefault(a,a);
    		int d=tm.getOrDefault(b,b);
    		tm.put(a,d);
    		tm.put(b,c);
    	}
    	int[] arr=new int[tm.size()];
    	int ind=0;
    	Map<Integer,Integer> m=new HashMap<>();
    	for(Map.Entry<Integer,Integer> e:tm.entrySet())
    	{
    		arr[ind++]=e.getValue();
    		m.put(arr[ind-1],ind);
    	}
    	mergesort(arr,0,tm.size()-1);
    	int i=0;
    	for(Map.Entry<Integer,Integer> e:tm.entrySet())
    	{
    		i++;
    		long a=Math.abs(e.getValue()-e.getKey()-1);
    		ind=tm.get(e.getValue());
    		long b=Math.abs(m.get(ind)-i-1);
    		ans+=a-b;
    	}
    	pw.print(ans);
    	pw.flush();
    }

    public static int[] mergesort(int[] arr,int l,int r)
    {
    	if(l==r)
    		return new int[]{arr[l]};
    	int m=(l+r)/2;
    	int[] a=mergesort(arr,l,m);
    	int[] b=mergesort(arr,m+1,r);
    	int n1=m-l+1,n2=r-m,i=0,j=0,k=0;
    	int[] arr1=new int[n1+n2];
    	while(i<n1 && j<n2)
    	{
    		if(a[i]>b[j])
    		{
    			ans+=n1-i;
    			arr1[k++]=b[j++];
    		}
    		else
    			arr1[k++]=a[i++];
    	}
    	while(i<n1)
    		arr1[k++]=a[i++];
    	while(j<n2)
    		arr1[k++]=b[j++];
    	return arr1;
    } 

    public static long inverse(long a)
    {
    	long r=1,p=mod-2;
    	while(p>0)
    	{
    		if(p%2==1)
    		{
    			r*=a;
    			r%=mod;
    		}
    		p>>=1;
    		a=(a*a)%mod;
    	}

    	return r;
    }

}

class pair<A,B>
{
    A f;
    B s;

    public pair(A a,B b)
    {
        f=a;
        s=b;
    }
}

class FastReader
{
    BufferedReader br;
    StringTokenizer st;
 
    public FastReader()
    {
        br=new BufferedReader(new InputStreamReader(System.in));
    }
 
    public String next() throws IOException
    {
        if(st==null || !st.hasMoreElements())
        {
            st=new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
 
    public int nextInt() throws IOException
    {
        return Integer.parseInt(next());
    }
 
    public long nextLong() throws IOException
    {
        return Long.parseLong(next());
    }
}