varn:longint;a,b:array[1..2000000] of longint;
procedureqsort(l,r:longint);vari,j,m,t:longint;
begini:=l;j:=r;m:=b[(l+r)div2];repeatwhile b[i]<m do inc(i);while b[j]>m do dec(j);if i<=j thenbegint:=a[i];a[i]:=a[j];a[j]:=t;t:=b[i];b[i]:=b[j];b[j]:=t;inc(i);dec(j);end;until i>j;if i<r then qsort(i,r);if l<j then qsort(l,j);
end;
vari,ans,sum:longint;
beginreadln(n);for i:=1to n doreadln(a[i],b[i]);qsort(1,n);ans:=b[1];for i:=2to n doif a[i]>=ans thenbegininc(sum);ans:=b[i];end;writeln(sum+1);
end.