import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); LinkedList<int[]> queue = new LinkedList<>(); sc.nextLine(); int end = 0; int count = 0; while(sc.hasNextLine()){ String[] str = sc.nextLine().split(" "); int a = Integer.parseInt(str[0]); int b = Integer.parseInt(str[1]); queue.add(new int[]{a,b}); } Collections.sort(queue,(s1,s2)->s1[1]-s2[1]); while(!queue.isEmpty()) { int[] e = queue.poll(); if(e[0]>=end){ count++; end = e[1]; } } System.out.println(count); } }