import java.util.Arrays; import java.util.Scanner; //52 /*右端点排序,按条件判断(倾向于选最右边的)*/ public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[][] a = new int[n][2]; for (int i = 0; i < n; i++) { a[i][0] = sc.nextInt(); a[i][1] = sc.nextInt(); } Arrays.sort(a, (a1, a2) -> a1[1] - a2[1]); // 右端点排序 int res = 2;// 至少需要两个 int temp = a[0][1]; for (int i = 1; i < n; i++) { if (a[i][0] > temp) { res += 2; temp = a[i][1]; } else if (a[i][0] == temp) { res += 1; temp = a[i][1]; } } System.out.println(res); } }