import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    static int N;

    static PriorityQueue<Class> classes;
    static PriorityQueue<Class> pq;
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;

    public static void main(String[] args) throws IOException {
        init();
        process();
        print();
    }

    private static void print() {
        System.out.println(pq.size());
    }

    private static void process() {

        for (Class c : classes) {

            if (pq.isEmpty()) {
                pq.add(c);
                continue;
            }

            Class earlyEndClass = pq.peek();

            // 강의실을 새로 배정해야하는 경우, (현재 진행하는 강의 중 이어서 할 수 있는 강의실이 없는 경우)
            if (earlyEndClass.end <= c.start) {
                pq.poll();
            }

            pq.add(c);
        }
    }

    public static void init() throws IOException {
        classes = new PriorityQueue<>(new Comparator<Class>() {
            @Override
            public int compare(Class o1, Class o2) {
                if (o1.start != o2.start) {
                    return o1.start - o2.start;
                }

                return o1.end - o2.end;
            }
        });

        pq = new PriorityQueue<>(new Comparator<Class>() {
            @Override
            public int compare(Class o1, Class o2) {
                return o1.end - o2.end;
            }
        });

        N = Integer.parseInt(br.readLine());

        for (int i = 0; i < N; i++) {
            st = new StringTokenizer(br.readLine());

            int start = Integer.parseInt(st.nextToken());
            int end = Integer.parseInt(st.nextToken());

            classes.add(new Class(start, end));
        }
    }


    public static class Class {
        int start;
        int end;

        public Class(int start, int end) {
            this.start = start;
            this.end = end;
        }
    }

}