A restaurant received n orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the i-th order is characterized by two time values — the start time li and the finish time ri (li ≤ ri).

Restaurant management can accept and reject orders. What is the maximal number of orders the restaurant can accept?

No two accepted orders can intersect, i.e. they can't share even a moment of time. If one order ends in the moment other starts, they can't be accepted both.

Input

The first line contains integer number n (1 ≤ n ≤ 5·105) — number of orders. The following n lines contain integer values li and ri each (1 ≤ li ≤ ri ≤ 109).

Output

Print the maximal number of orders that can be accepted.

Examples

Input

2
7 11
4 7


Output

1


Input

5
1 2
2 3
3 4
4 5
5 6


Output

3


Input

6
4 8
1 5
4 7
2 5
1 3
6 8


Output

2
//http://codeforces.com/contest/569/problem/A
import java.io.IOException;
import java.util.*;

public class Main {

     public static class Pair {
        int left;
        int right;
        public Pair (int left, int right) {
            this.left = left;
            this.right = right;
        }

         @Override
         public String toString() {
             return "" + left + " " + right;
         }
     }

    public static int [] RESULT_TABLE;
    public static int solve(Pair[] list) {
        Stack<Pair> orders = new Stack<>();
        for (int i = 0; i < list.length; i++) {
            if (orders.size() == 0) orders.push(list[i]);
            Pair pair = orders.lastElement();
            if (pair.right < list[i].left) {
                orders.push(list[i]);
            }

        }
        int max = orders.size();
        orders.clear();
        for (int i = list.length -1; i >=0; i--) {
            if (orders.size() == 0) orders.push(list[i]);
            Pair pair = orders.lastElement();
            if (pair.left > list[i].right) {
                orders.push(list[i]);
            }

        }
        return orders.size() > max ? orders.size() : max;
    }

    public static void main(String[] args) throws IOException {

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Pair[] list = new Pair[n];
        RESULT_TABLE = new int[n];

        for (int i = 0; i < n ; i++) {
            int left = scanner.nextInt();
            int right = scanner.nextInt();
            Pair pair = new Pair(left, right);
            list[i] = pair;
        }
        Arrays.sort(list, new Comparator<Pair>() {
            @Override
            public int compare(Pair o1, Pair o2) {
                if (o1.left != o2.left) {
                    return o1.left - o2.left;
                } else {
                    return o1.right - o2.right;
                }
            }
        });

        System.out.println(solve(list));


    }
}