package tree;
import java.util.HashMap;
import java.util.Scanner;
/*
* 5 10
4 10
0 2
1 6
5 9
3 4
*/
public class Week21 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int edgeNum = Integer.parseInt(scanner.nextLine().split(" ")[0]);
int []inputB = new int[edgeNum * 2];
int []inputA = new int[edgeNum * 2];
int inputIndex = 0;
int pasteIndex = 1;
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
HashMap<Integer, Integer> sum = new HashMap<Integer, Integer>();
for(int i=0; i<edgeNum; i++){
String data = scanner.nextLine();
int horizon = Integer.parseInt(data.split(" ")[0]);
int vertical = Integer.parseInt(data.split(" ")[1]);
inputB[inputIndex++] = horizon;
inputB[inputIndex--] = vertical;
inputA[inputIndex++] = horizon;
inputA[inputIndex++] = vertical;
}
scanner.close();
mergeSort(inputA, 0, inputA.length-1);
maping(inputA, map);
node21 root = creSegTree(0, inputB.length - 1);
for(int i=0; i<inputB.length; i++){
int left = inputB[i++];
int right = inputB[i];
left = map.get(left);
right = map.get(right) - 1;
paste(root, left, right, map, pasteIndex++);
}
dfs(root, sum);
System.out.println(sum.size());
}
public static void mergeSort(int []input, int start, int end){
if(start < end){
int middle = (start + end) / 2;
mergeSort(input, start, middle);
mergeSort(input, middle + 1, end);
int []temp1 = new int[middle - start + 1];
int index1 = 0;
for(int i=0; i<temp1.length; i++) temp1[i] = input[start + i];
int []temp2 = new int[end - middle];
int index2 = 0;
for(int i=0; i<temp2.length; i++) temp2[i] = input[middle + 1 + i];
for(int i=start; i<end+1; i++){
if(temp1[index1] <= temp2[index2]) input[i] = temp1[index1++];
else input[i] = temp2[index2++];
if(index1 == temp1.length){
for(int j=i+1; j<end+1; j++) input[j] = temp2[index2++];
break;
}
else if(index2 == temp2.length){
for(int j=i+1; j<end+1; j++) input[j] = temp1[index1++];
break;
}
}
}
}
public static void maping(int []inputA, HashMap<Integer, Integer> map){
for(int i=0; i<inputA.length; i++){
map.put(inputA[i], i);
}
}
public static node21 creSegTree(int left, int right){
node21 node = new node21(left, right);
if(left != right){
node21 leftchild = creSegTree(left, (left + right) /2);
node21 rightchild = creSegTree((left + right) / 2 + 1, right);
node.leftChild = leftchild;
node.rightChild = rightchild;
return node;
}
else{
node.Value = -1;
return node;
}
}
public static void paste(node21 root, int left, int right, HashMap<Integer, Integer> map, int index){
if(left == root.leftBound && right == root.rightBound){
root.lazyTag = index;
}
else{
if(root.lazyTag != 0){
root.leftChild.lazyTag = root.lazyTag;
root.rightChild.lazyTag = root.lazyTag;
root.lazyTag = 0;
}
if(right < (root.leftBound + root.rightBound) / 2 + 1) paste(root.leftChild, left, right, map, index);
else if (left > (root.leftBound + root.rightBound) / 2) paste(root.rightChild, left, right, map, index);
else{
paste(root.leftChild, left, (root.leftBound + root.rightBound) / 2, map, index);
paste(root.rightChild, (root.leftBound + root.rightBound) / 2 + 1, right, map, index);
}
}
}
public static void dfs(node21 root, HashMap<Integer, Integer> sum){
if(root.lazyTag != 0){
sum.put(root.lazyTag, 1);
return;
}
if(root.leftChild != null) dfs(root.leftChild, sum);
if(root.rightChild != null) dfs(root.rightChild, sum);
}
class node21{
int leftBound;
int rightBound;
int Value;
node21 leftChild;
node21 rightChild;
int lazyTag;
public node21(int leftBound, int rightBound){
this.leftBound = leftBound;
this.rightBound = rightBound;
}
}