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
//package Test12;

import java.util.Arrays;
import java.util.Hashtable;
import java.util.Scanner;

public class q2 
{

    public static void main(String args[])
    {
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        pair[] p=new pair[n];
        long[] tmp=new long[2*n+1];
        tmp[2*n]=0;
        for(int i=0;i<n;i++)
        {
            long st=s.nextLong();
            long e=s.nextLong();
            tmp[2*i]=st;
            tmp[2*i+1]=e;
            p[i]=new pair(st,e);
        }
        
        Arrays.sort(tmp);
        
        Hashtable<Long, Integer> h=new Hashtable<Long, Integer>();
        
        for(int i=0;i<=2*n;i++)
        {
            h.put(tmp[i], i);
        }
    //  System.out.println(h);
        for(int i=0;i<n;i++)
        {
            p[i].s=h.get(p[i].s);
            p[i].e=h.get(p[i].e);
        }
            
        Arrays.sort(p);
        int[] dp=new int[2*n+1];
        SegTree seg=new SegTree(dp, 0);
        
        for(int i=0;i<n;i++)
        {
            int tmpans=seg.query(0, (int)p[i].s);
            tmpans++;
            dp[(int)p[i].e]=Math.max(dp[(int)(p[i].e)], tmpans);
            seg.upd((int)(p[i].e), dp[(int)(p[i].e)]);
        }
        
        System.out.println(seg.query(0, 2*n+1));
    }
    
    static class pair implements Comparable<pair>
    {
        long s,e;
        public pair(long s,long e)
        {
            this.s=s;
            this.e=e;
        }
        @Override
        public int compareTo(pair o) {
            // TODO Auto-generated method stub
            if(this.e!=o.e)
            return (int)(this.e-o.e);
            else
                return (int)(this.s-o.s);
        }
        
        
    }
    
    
    static class SegTree
    {
        static int seg[];
        static int dp[];
        int n;
        int d;
        public SegTree(int[] arr,int defaul)
        {
            this.dp=arr;
            n=dp.length;
            seg=new int[4*arr.length];
            build(1,0,n);
            this.d=defaul;
        }

        public void build(int id,int l,int r){
            if(r-l<2){
                seg[id]=dp[l];
                return;
            }
            int mid=(l+r)/2;
            build(2*id,l,mid);
            build(2*id+1,mid,r);
            seg[id]=merge(seg[2*id],seg[2*id+1]);
        }

        public int query(int l,int r)
        {
            return givemin(1,l,r,0,n);
        }

        public  int givemin(int id,int x,int y,int l,int r){
            if(x<=l && y>=r){
                return seg[id];
            }
            if(y<=l || r<=x){
                return d;
            }
            int mid=(l+r)/2;
            return merge(givemin(2*id, x, y, l, mid),givemin(2*id+1, x, y, mid, r));
        }

        public int upd(int id,int value)
        {
            return update(1,id,value,0,n);
        }
        public  int update(int id,int p,int value,int l,int r){
            if(r-l<2){
                dp[p]=value;
                seg[id]=value;
                return value;
            }
            int mid=(l+r)/2;
            if(p<mid){
                update(2*id, p, value, l, mid);
                seg[id]=merge(seg[2*id], seg[2*id+1]);
                return seg[id];
            }
            else{
                update(2*id+1, p, value, mid,r);
                seg[id]=merge(seg[2*id+1], seg[2*id]);
                return seg[id];

            }
        }

        public int merge(int l,int r)
        {

            //set initial value
            return Math.max(l, r);
        }
    }

}
