`
import java.io.;
import java.lang.;
import java.util.*;
public class Main {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
static StringTokenizer stz = new StringTokenizer(“”);
static String next() throws Exception{
if(!stz.hasMoreTokens()) stz = new StringTokenizer(nextLine());
return stz.nextToken();
}
static String nextLine() throws Exception{
return br.readLine();
}
static int nI() throws Exception{
return Integer.parseInt(next());
}
static void flush() throws Exception{
bw.flush();
}
static void write(String str) throws Exception{
bw.write(str);
}
class Range{
public int l, r;
Range(int l, int r){
this.l = l;
this.r = r;
}
}
public void run() throws Exception{
int n = nI();
Range[ ] ranges = new Range[n];
for(int i = 0; i < n; i++){
ranges[i] = new Range(nI(), nI());
}
Arrays.sort(ranges, ((o1, o2) -> o1.l - o2.l));
PriorityQueue<Integer> q = new PriorityQueue<>();
for(int i = 0; i < n; i++){
if (q.isEmpty() || q.peek() >= ranges[i].l) q.add(ranges[i].r); // 需要添加一个新的组
else {// 更新一下新加入以后的右边界
q.poll();
q.add(ranges[i].r);
}
}
write(q.size()+"\n");
flush();
}
public static void main(String[] args) throws Exception{
new Main().run();
}
}
`