1 /**************************************************************
2 Problem: 3433
3 User: HansBug
4 Language: Pascal
5 Result: Accepted
6 Time:0 ms
7 Memory:304 kb
8 ****************************************************************/
9
10 var
11 i,j,k,l,m,n,ans,l1,l2:longint;
12 a:array[0..10000,1..2] of longint;
13 procedure swap(var x,y:longint);
14 var z:longint;
15 begin
16 z:=x;x:=y;y:=z;
17 end;
18 procedure sort(l,r:longint);
19 var i,j,x,y:longint;
20 begin
21 i:=l;j:=r;x:=a[(l+r) div 2,2];
22 repeat
23 while a[i,2]<x do inc(i);
24 while a[j,2]>x do dec(j);
25 if i<=j then
26 begin
27 swap(a[i,1],a[j,1]);
28 swap(a[i,2],a[j,2]);
29 inc(i);dec(j);
30 end;
31 until i>j;
32 if i<r then sort(i,r);
33 if l<j then sort(l,j);
34 end;
35
36 begin
37 readln(n);
38 for i:=1 to n do readln(a[i,1],a[i,2]);
39 sort(1,n);
40 for i:=1 to n do
41 begin
42 if (a[i,1]>=l1) then
43 begin
44 l1:=a[i,2];
45 inc(ans);
46 end
47 else if (a[i,1]>=l2) then
48 begin
49 l2:=a[i,2];
50 inc(ans);
51 end;
52 if l1<l2 then swap(l1,l2);
53 end;
54 writeln(ans);
55 readln;
56 end.