#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<ll>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  int n;
  cin >> n;
  pair<int,int> k[n];
  rep(i,n){
    int a,b;
    cin >> a >> b;
    k[i]=make_pair(a,b);
  }
  sort(k,k+n);
  int u[n];
  u[n-1]=k[n-1].second;
  rep(i,n-1){
    u[n-2-i]=min(u[n-1-i],k[n-2-i].second);
  }
  int v[n];
  v[0]=k[0].second;
  rep(i,n-1){
    u[i+1]=min(u[i],k[i+1].second);
  }
  int ans=0;
  rep()
}   
