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

import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;


public class Main {

    static StringBuilder a = new StringBuilder();

    public static void main(String[] args) throws IOException {
        //BufferedReader in = new BufferedReader(new InputStreamReader(System.in));                                    //(new FileReader("input.in"));
        //StringBuilder out = new StringBuilder();
        //StringTokenizer tk;
        // Scanner Reader = new Scanner(System.in);
        Reader.init(System.in);
        int n = Reader.nextInt();
        ArrayList<Point> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int x = Reader.nextInt(),y=Reader.nextInt();
           
            a.add(new Point(x, y));
        }
        

      Collections.sort(a);
        int lx=0,x,c=0;
        for (int i = 0; i < a.size(); i++) {
            if(a.get(i).x>lx){
            c++;
            lx=a.get(i).y;
            }
       
        }

        System.out.println(c);

    }

}

class Point implements Comparable<Point> {

    int x, y;

    public Point(int a, int b) {
        x = a;
        y = b;

    }

    @Override
    public boolean equals(Object object) {
        boolean sameSame = false;

        if (object != null && object instanceof Point) {
            sameSame = this.x == ((Point) object).x;
        }
     

        return sameSame;
    }

 
    @Override
    public int compareTo(Point o) {
        return this.y-o.y;
    }
}

//class Book {
//
//    String a;
//    int b, c,ind;
//
//    public Book(String x, int y) {
//        a = x;
//        b = y;
//        
//
//    }
//
//    @Override
//    public boolean equals(Object object) {
//        boolean sameSame = false;
//
//        if (object != null && object instanceof Book) {
//            sameSame = (this.a == null ? ((Book) object).a == null : this.a.equals(((Book) object).a));
//        }
//        if (object != null && object instanceof Book) {
//            sameSame = this.b == ((Book) object).b;
//        }
//
//        return sameSame;
//    }
//}
//


class Reader {

    static StringTokenizer tokenizer;
    static BufferedReader reader;

    public static void init(InputStream input) throws UnsupportedEncodingException {
        reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));
        tokenizer = new StringTokenizer("");
    }

    public static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    public static String nextLine() throws IOException {
        return reader.readLine();
    }

    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    public static long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}
