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).
// practice with rainboy
import java.io.*;
import java.util.*;

public class CF540E extends PrintWriter {
	CF540E() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF540E o = new CF540E(); o.main(); o.flush();
	}

	int[] tr;
	void update(int i, int n, int x) {
		while (i < n) {
			tr[i] += x;
			i |= i + 1;
		}
	}
	int query(int i) {
		int x = 0;
		while (i >= 0) {
			x += tr[i];
			i &= i + 1; i--;
		}
		return x;
	}
	void main() {
		int n = sc.nextInt();
		int[] xx = new int[n * 2];
		Integer[] ii = new Integer[n * 2];
		int[] aa = new int[n];
		int[] bb = new int[n];
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			xx[aa[i] = i << 1] = a;
			xx[bb[i] = i << 1 | 1] = b;
		}
		for (int i = 0; i < n * 2; i++)
			ii[i] = i;
		Arrays.sort(ii, (i, j) -> xx[i] - xx[j]);
		int[] kk = new int[n * 2 * 2];
		int m = 0;
		for (int i = 0, j, x_ = -1; i < n * 2; i = j) {
			int x = xx[ii[i]];
			j = i + 1;
			while (j < n * 2 && xx[ii[j]] == x)
				j++;
			int k;
			if (x_ != -1 && (k = x - x_ - 1) > 0)
				kk[m++] = k;
			for (int h = i; h < j; h++)
				xx[ii[h]] = m;
			kk[m++] = 1;
			x_ = x;
		}
		int[] pp = new int[m];
		for (int h = 0; h < m; h++)
			pp[h] = h;
		for (int i = 0; i < n; i++) {
			int a = xx[aa[i]];
			int b = xx[bb[i]];
			int tmp = pp[a]; pp[a] = pp[b]; pp[b] = tmp;
		}
		tr = new int[m];
		long ans = 0;
		for (int h = 0; h < m; h++) {
			int i = m - 1 - pp[h], k = kk[h];
			ans += (long) query(i) * k;
			update(i, m, k);
		}
		println(ans);
	}
}
