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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class C597B {

    public static void main(String[] args) throws Exception {
        new C597B().run();
        out.close();
    }

    void run() throws Exception {
        int n = nextInt();
        ComparablePair<Integer, Integer>[] ends = new ComparablePair[n];
        for (int i = 0; i < n; ++i) {
            int l = nextInt();
            ends[i] = new ComparablePair<>(l, nextInt());
        }
        Arrays.sort(ends);
        int[] minPos = new int[n + 1];
        Arrays.fill(minPos, Integer.MAX_VALUE);
        minPos[0] = Integer.MIN_VALUE;
        int res = 0;
        for (int i = 0; i < n; ++i) {
            int prevRes = Arrays.binarySearch(minPos, ends[i].first - 1);
            if (prevRes < 0) {
                prevRes = - (prevRes + 1) - 1;
            }
            res = Math.max(res, prevRes + 1);
            minPos[prevRes + 1] = Math.min(minPos[prevRes + 1], ends[i].second);
        }
        out.print(res);
    }
    
    public class ComparablePair<A extends Comparable<A>, B extends Comparable<B>> implements Comparable<ComparablePair<A, B>> {

    public ComparablePair(A first, B second) {
        this.first = first;
        this.second = second;
    }

    public A first;
    public B second;

    @Override
    public int compareTo(ComparablePair<A, B> o) {
        int comp = first.compareTo(o.first);
        if (comp == 0) {
            return second.compareTo(o.second);
        }
        return comp;
    }
        
    @Override
    public String toString() {
        return "(" + first + ", " + second + ")";
    }
}
    
//~~~~~~~~~~~~~~~~~~~~~~~~~~~ template ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    int[] nextIntArray(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; ++i) {
            res[i] = nextInt();
        }
        return res;
    }

    int[][] nextIntArray(int nx, int ny) throws IOException {
        int[][] res = new int[nx][ny];
        for (int i = 0; i < nx; ++i) {
            for (int j = 0; j < ny; ++j) {
                res[i][j] = nextInt();
            }
        }
        return res;
    }

    long[] nextLongArray(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; ++i) {
            res[i] = nextLong();
        }
        return res;
    }

    long[][] nextLongArray(int nx, int ny) throws IOException {
        long[][] res = new long[nx][ny];
        for (int i = 0; i < nx; ++i) {
            for (int j = 0; j < ny; ++j) {
                res[i][j] = nextLong();
            }
        }
        return res;
    }
    
    int[][] newIntArray(int nx, int ny, int val) {
        int[][] res = new int[nx][ny];
        for (int i = 0; i < nx; ++i) {
            Arrays.fill(res[i], val);
        }
        return res;
    }

    int[][][] newIntArray(int nx, int ny, int nz, int val) {
        int[][][] res = new int[nx][ny][nz];
        for (int i = 0; i < nx; ++i) {
            for (int j = 0; j < ny; ++j) {
                Arrays.fill(res[i][j], val);
            }
        }
        return res;
    }

    long[][] newLongArray(int nx, int ny, long val) {
        long[][] res = new long[nx][ny];
        for (int i = 0; i < nx; ++i) {
            Arrays.fill(res[i], val);
        }
        return res;
    }

    long[][][] newLongArray(int nx, int ny, int nz, long val) {
        long[][][] res = new long[nx][ny][nz];
        for (int i = 0; i < nx; ++i) {
            for (int j = 0; j < ny; ++j) {
                Arrays.fill(res[i][j], val);
            }
        }
        return res;
    }

    String nextToken() throws IOException {
        while (strTok == null || !strTok.hasMoreTokens()) {
            String line = in.readLine();
            if (line == null) {
                return null;
            }
            strTok = new StringTokenizer(line);
        }
        return strTok.nextToken();
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    
    static StringTokenizer strTok;
    final static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    final static PrintWriter out = new PrintWriter(System.out);
}
