// Arup Guha
// 12/19/2019
// Solution to January 14 Silver USACO Problem: Moolympics

import java.util.*;
import java.io.*;

public class recording {

	public static void main(String[] args) throws Exception {

		// Read in the events.
		Scanner stdin = new Scanner(new File("recording.in"));
		int n = stdin.nextInt();
		event[] shows = new event[n];
		for (int i=0; i<n; i++) {
			int s = stdin.nextInt();
			int e = stdin.nextInt();
			shows[i] = new event(s, e);
		}
		
		// Sort by end time.
		Arrays.sort(shows);
		
		// Shows we are recording.
		int res = 0;
		
		// Times are recorders are free.
		int tA = 0, tB = 0;
		
		// Greedily go through the events in this order.
		for (int i=0; i<n; i++) {
			
			// Can't fit this show on either recorder.
			if (shows[i].start < tA && shows[i].start < tB) continue;
			
			// Forced to put on recorder B.
			else if (shows[i].start < tA) {
				tB = shows[i].end;
				res++;
			}
			
			// Forced to put on recorder B.
			else if (shows[i].start < tB) {
				tA = shows[i].end;
				res++;
			}
			
			// We can choose both recorders, so we want to put it on the one with a later
			// end time to give more freedom for future recordings.
			else if (tA > tB) {
				tA = shows[i].end;
				res++;
			}
			
			// This is the recorder that ends later...
			else {
				tB = shows[i].end;
				res++;				
			}
		}
		
		// Write out the result.
		PrintWriter out = new PrintWriter(new FileWriter("recording.out"));
		out.println(res);
		out.close();
		stdin.close();
	}
}

// Events sorted by end time.
class event implements Comparable<event> {
	
	public int start;
	public int end;
	
	public event(int s, int e) {
		start = s;
		end = e;
	}
	
	public int compareTo(event other) {
		return end - other.end;
	}
}