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.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        QuickScanner in = new QuickScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskB {
    public class Restaurant implements  Comparable<Restaurant>
    {
        int l, r;
        Restaurant(int l, int r)
        {
            this.l=l;
            this.r=r;
        }

        public int compareTo(Restaurant restaurant)
        {
            return l-restaurant.l;
        }
    }
    ArrayList<Restaurant> rest;
    int n;
    Integer dp[];

    int getFirstGE(int L)
    {
        int lb=0;
        int rb=rest.size();
        while(lb<rb)
        {
            int mid=(lb+rb)/2;
            if(rest.get(mid).l>=L)
                rb=mid;
            else
                lb=mid+1;
        }
        return lb;
    }


    public void solve(int testNumber, QuickScanner in, PrintWriter out) {
        rest=new ArrayList<Restaurant>();
        n=in.nextInt();
        for(int i=0;i<n;i++)
            //rest.add(new Restaurant(i,i));
            rest.add(new Restaurant(in.nextInt(), in.nextInt()));
        Collections.sort(rest);
        dp=new Integer[n];
        for(int i=n-1;i>=0;i--)
            solve(i);
        out.println(solve(0));
    }
    int solve(int cur)
    {
        if(cur==n) return 0;
        if(dp[cur]==null)
        {
            dp[cur]=Math.max(solve(cur+1), solve(getFirstGE(rest.get(cur).r+1))+1);
        }
        return dp[cur];
    }
}

class QuickScanner {
    BufferedReader in;
    StringTokenizer token;
    String delim;
    public QuickScanner(InputStream inputStream)
    {
        this.in=new BufferedReader(new InputStreamReader(inputStream));
        this.delim=" \n\t";
        this.token=new StringTokenizer("",delim);
    }

    public boolean hasNext()
    {
        while(!token.hasMoreTokens())
        {
            try {
                String s=in.readLine();
                if(s==null) return false;
                token=new StringTokenizer(s,delim);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }
        return true;
    }

    public String next()
    {
        hasNext();
        return token.nextToken();
    }

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

}
