#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define len length()
#define sqr(x) x*x
#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define bp(x) __builtin_popcount(x)
#define INF numeric_limits<long long int>::max()
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define frp freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
const int maxn = (int)1e6;
const int mod = (int)1e9 + 7;
using namespace std;
int n;
int cnt;
bool ok=false;
vector<pair<int,int> > v;
main(){
scanf("%d",&n);
for(int i=0; i < n; i++){
int x,y;
scanf("%d%d",&x,&y);
v.pb(mp(y,x));
}
sort(all(v));
//puts("");
for(int i=1; i < n; i++){
if(v[i-1].F == v[i].F){
ok=true;
break;
}
}
if(ok){
for(int i=0; i < n; i++){
swap(v[i].F,v[i].S);
}
sort(all(v));
for(int i=1; i < n; i++){
if(v[i-1].F < v[i].S)
cnt++;
}
printf("%d",cnt);
}
else{
for(int i=1; i < n; i++){
if(v[i-1].F < v[i].S)
cnt++;
}
printf("%d",cnt);
}
return 0;
}
//by ELDAN
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CgojZGVmaW5lIEYgZmlyc3QKI2RlZmluZSBTIHNlY29uZAojZGVmaW5lIGxsIGxvbmcgbG9uZwojZGVmaW5lIGxlbiBsZW5ndGgoKSAgICAgICAgICAgICAKI2RlZmluZSBzcXIoeCkgeCp4CiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgbXAgbWFrZV9wYWlyCiNkZWZpbmUgc3ooeCkgKChpbnQpICh4KS5zaXplKCkpCiNkZWZpbmUgYWxsKHgpIHguYmVnaW4oKSwgeC5lbmQoKQojZGVmaW5lIGFsbHIoeCkgeC5yYmVnaW4oKSwgeC5yZW5kKCkKI2RlZmluZSBicCh4KSBfX2J1aWx0a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