import java.util.Arrays; import java.util.Scanner; public class Main0001 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n = sc.nextInt(); mac[] m = new mac[n+1]; for(int i=1;i<=n;i++) { int a = sc.nextInt(); int b = sc.nextInt(); m[i] = new mac(a,b); } Arrays.sort(m,1,n+1); int[] arr = new int[n+1]; arr[1] = m[1].ed; int k = 1; for(int i=2;i<=n;i++) { for(int j=1;j<=k;j++) { if(arr[j]<=m[i].st) { arr[j] = m[i].ed; break; }else if(j==k){ k++; arr[k] = m[i].ed; break; } } } System.out.println(k); } } } class mac implements Comparable<mac>{ int st; int ed; public mac(int st,int ed) { this.st = st; this.ed = ed; } @Override public int compareTo(mac m) { return st-m.st; } }