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.Arrays;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.ArrayList;

public class B { 

    private static class Line implements Comparable<Line> { 
        int begin; 
        int end;

        public Line(int begin, int end) { 
            this.begin = begin;
            this.end = end;
        }

        @Override
        public int compareTo(Line other) { 
            if(begin < other.begin)
                return -1;

            if(begin > other.begin)
                return 1;
            
            return end - other.end;
        }
    }

    static int solve(Line [] lines) { 
        Arrays.sort(lines);

        List<Line> finalLines = new ArrayList<Line>();

        for(int i=0; i<lines.length; i++) { 
            if(i == 0) {
                finalLines.add(lines[i]);
                continue;
            }

            if(lines[i].begin == lines[i-1].begin) { 
                continue;
            }

            finalLines.add(lines[i]);

        }
        
        /*for(int i=0; i<finalLines.size(); i++) { 
            System.out.println(i + " : " + finalLines.get(i).begin + " " + finalLines.get(i).end);
        }*/

        int counter = 0;
        

        for(int i=0; i<finalLines.size(); i++) { 

            if(i == finalLines.size() -1) { 
                //System.out.println("Picking line " + i);
                counter++;
                continue;
            }
            Line currLine = finalLines.get(i);
            
            Line nextLine = finalLines.get(1 + i);
            
            
            if(currLine.end < nextLine.begin) {
                counter++;
                //System.out.println("Picking line " + i);
                continue;
            }
            
            int nextInd = 1 + i;

            while(currLine.end <= nextLine.end &&  currLine.end >= nextLine.begin && nextInd + 1 < finalLines.size()) { 
                nextInd++;
                nextLine = finalLines.get(nextInd);
                
            }
            
            if(currLine.end < nextLine.begin) {
                counter++;
                //System.out.println("Picking line " + i);
                i = nextInd - 1;
                continue;
            }
            
            //System.out.println("Considering between line " + i + " and line " + nextInd);
            boolean doesCoverMore = doesCoverMore(finalLines, i);
            if(!doesCoverMore) { 
            //  System.out.println("Picking line " + i);
                i = nextInd;
                counter++;
                

            } else { 
                i = nextInd - 1;
            }


        }
        return counter;
    }

    static boolean doesCoverMore(List<Line> lines, int index) { 
        if(index >= lines.size() - 2)
            return false;
        
        Line currLine = lines.get(index);
        Line nnLine = lines.get(index+2);
    
        return nnLine.begin <= currLine.end;
    }
    
    public static void main(String [] args) throws IOException { 


        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int N = Integer.parseInt(br.readLine());
        
        Line [] lines = new Line[N];
        
        for(int i=0; i<N; i++) { 
            
            String [] parts = br.readLine().split(" ");
            
            int begin = Integer.parseInt(parts[0]);
            int end = Integer.parseInt(parts[1]);
            
            lines[i] = new Line(begin, end);
        }
        
        int sol = solve(lines);
        
        System.out.println(sol);
    }


    
    
}