#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 5;
const int MAX = 1e6 + 6;
vector < int > v[MAX];
int x , y;
int n;
int ans;
int bit[2][MAX];
vector < int > ys;
set < int > s;
void update(int k , int idx , int val){
while(idx < MAX){
bit[k][idx] += val;
idx += idx & -idx;
}
}
int query(int k , int idx){
int res = 0;
while(idx){
res += bit[k][idx];
idx -= idx & -idx;
}
return res;
}
inline int get(int a , int b , int c , int d){
return max(max(a , b) , max(c , d));
}
inline int cost(int y){
int lftu = query(0 , y);
int lftd = query(0 , MAX - 1) - lftu;
int rgtu = query(1 , y);
int rgtd = query(1 , MAX - 1) - rgtu;
return get(lftu , lftd , rgtu , rgtd);
}
int main(){
freopen("balancing.in" , "r" , stdin);
freopen("balancing.out" , "w" , stdout);
scanf("%d" , &n);
memset(bit , 0 , sizeof(bit));
for(int i = 1 ; i <= n ; ++i){
scanf("%d %d" , &x , &y);
assert(y > 0);
assert(x > 0);
s.insert(y);
update(1 , y , 1);
v[x].emplace_back(y);
}
ys.clear();
for(int x : s){
ys.emplace_back(x);
}
ans = n;
for(int x = 1 ; x < MAX ; ++x){
if(v[x].empty()){
continue;
}
sort(v[x].begin() , v[x].end());
for(int y : v[x]){
update(0 , y , 1);
update(1 , y , -1);
}
int l = 0;
int r = int(ys.size()) - 1;
while(l + 3 < r){
int mid1 = l + l + r;
int mid2 = l + r + r;
mid1 /= 3;
mid2 /= 3;
int x = cost(ys[mid1]);
int y = cost(ys[mid2]);
ans = min(ans , min(x , y));
if(x <= y){
r = mid2;
}
else{
l = mid1;
}
}
for(int i = l ; i <= r ; ++i){
ans = min(ans , cost(ys[i]));
}
}
printf("%d\n" , ans);
}
I2luY2x1ZGUgImJpdHMvc3RkYysrLmgiCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBOID0gMWU1ICsgNTsKY29uc3QgaW50IE1BWCA9IDFlNiArIDY7CnZlY3RvciA8IGludCA+IHZbTUFYXTsKaW50IHggLCB5OwppbnQ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ZCIgLCAmeCAsICZ5KTsKICAgICAgICBhc3NlcnQoeSA+IDApOwogICAgICAgIGFzc2VydCh4ID4gMCk7CiAgICAgICAgcy5pbnNlcnQoeSk7CiAgICAgICAgdXBkYXRlKDEgLCB5ICwgMSk7CiAgICAgICAgdlt4XS5lbXBsYWNlX2JhY2soeSk7CiAgICB9CiAgICB5cy5jbGVhcigpOwogICAgZm9yKGludCB4IDogcyl7CiAgICAgICAgeXMuZW1wbGFjZV9iYWNrKHgpOwogICAgfQogICAgYW5zID0gbjsKICAgIGZvcihpbnQgeCA9IDEgOyB4IDwgTUFYIDsgKyt4KXsKICAgICAgICBpZih2W3hdLmVtcHR5KCkpewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICB9CiAgICAgICAgc29ydCh2W3hdLmJlZ2luKCkgLCB2W3hdLmVuZCgpKTsKICAgICAgICBmb3IoaW50IHkgOiB2W3hdKXsKICAgICAgICAgICAgdXBkYXRlKDAgLCB5ICwgMSk7CiAgICAgICAgICAgIHVwZGF0ZSgxICwgeSAsIC0xKTsKICAgICAgICB9CiAgICAgICAgaW50IGwgPSAwOwogICAgICAgIGludCByID0gaW50KHlzLnNpemUoKSkgLSAxOwogICAgICAgIHdoaWxlKGwgKyAzIDwgcil7CiAgICAgICAgICAgIGludCBtaWQxID0gbCArIGwgKyByOwogICAgICAgICAgICBpbnQgbWlkMiA9IGwgKyByICsgcjsKICAgICAgICAgICAgbWlkMSAvPSAzOwogICAgICAgICAgICBtaWQyIC89IDM7CiAgICAgICAgICAgIGludCB4ID0gY29zdCh5c1ttaWQxXSk7CiAgICAgICAgICAgIGludCB5ID0gY29zdCh5c1ttaWQyXSk7CiAgICAgICAgICAgIGFucyA9IG1pbihhbnMgLCBtaW4oeCAsIHkpKTsKICAgICAgICAgICAgaWYoeCA8PSB5KXsKICAgICAgICAgICAgICAgIHIgPSBtaWQyOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2V7CiAgICAgICAgICAgICAgICBsID0gbWlkMTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmb3IoaW50IGkgPSBsIDsgaSA8PSByIDsgKytpKXsKICAgICAgICAgICAgYW5zID0gbWluKGFucyAsIGNvc3QoeXNbaV0pKTsKICAgICAgICB9CiAgICB9CiAgICBwcmludGYoIiVkXG4iICwgYW5zKTsKfQ==