import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Comparator;
import java.util.PriorityQueue;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StreamTokenizer st = new StreamTokenizer(br);
PriorityQueue<int[]> heap = new PriorityQueue<>(
Comparator.comparingInt(a -> a[1])
);
st.nextToken();
int n = (int)st.nval;
for (int i = 0; i < n; i++) {
st.nextToken();
int a = (int)st.nval;
st.nextToken();
int b = (int)st.nval;
heap.add(new int[] {a, b});
}
int count = 0;
int end = 0;
while (!heap.isEmpty()) {
int[] pre = heap.remove();
if (pre[0] >= end) {
count++;
end = pre[1];
}
}
System.out.println(count);
}
}