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 com.sun.prism.shader.Solid_TextureYV12_AlphaTest_Loader;
import javafx.util.Pair;
import org.omg.Messaging.SYNC_WITH_TRANSPORT;
import org.omg.Messaging.SyncScopeHelper;

import java.math.BigInteger;
import java.util.*;
import java.io.*;
import java.util.Collections;
import java.util.Collection;
public class Main {
    public static boolean overlapp(int x1,int x2,int y1,int y2){
        return  Math.max(x1,y1) <= Math.min(x2,y2);
    }
    public static class number{
        Integer a;
        Integer b;
        Integer len;
        public number(int aa,int bb){
            a=aa;
            b=bb;
            len=bb-aa;
        }
    }
    public static class Pair implements Comparable<Pair>
    {
        int first,second;

        public Pair(int f, int s)
        {
            first = f;
            second = s;
        }

        public Pair(Pair p)
        {
            first = p.first;
            second = p.second;
        }

        @Override
        public int compareTo(Main.Pair p1)
        {

            if (first == p1.first)
                return  second - p1.second;
            return first - p1.first;

        }

 }
    public static void main(String[] args) throws IOException {
            // TODO Auto-generated method stub
              Scanner S = new Scanner(System.in);
              int n=S.nextInt();
              ArrayList<Pair> all = new ArrayList<Pair>();
        for (int i = 0; i < n; i++) {
            all.add(new Pair(S.nextInt(),S.nextInt()));
            }
           Collections.sort(all);
        Pair temp = all.get(0);
        int res = 1;
        int f = temp.first;
        int s = temp.second;

        for (int i=1;i < n;++i)
        {
            temp = all.get(i);

            if (temp.first > f && temp.second < s)
            {
                f = temp.first;
                s = temp.second;
            }
            else
            if (temp.first > s)
            {
                ++res;
                f = temp.first;
                s = temp.second;
            }
        }
        System.out.println(res);
    }


}



