1 #include<cstdio>
2 #include<iostream>
3 #include<algorithm>
4 using namespace std;
5
6 struct edge{
7 int l,r,val;
8 }e[10000];
9
10 bool cmp(const edge &a,const edge &b){
11 return a.r < b.r;
12 }
13
14 int main(){
15 int n,a,b;
16 scanf("%d",&n);
17
18 for(int i = 1;i <= n;i++){
19 scanf("%d%d",&a,&b);
20 if(a > b) swap(a,b);
21 e[i].l = a+2000;
22 e[i].r = b+2000;
23 }
24
25 sort(e+1,e+1+n,cmp);
26
27 int last = 0,ans = 0;
28 for(int i = 1;i <= n;i++){
29 if(e[i].l > last) ans++,last = e[i].r-1;
30 }
31
32 printf("%d",ans);
33
34 return 0;
35 }