#include<iostream>
#include<fstream>
#include<cstring>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include <functional>
#include<map>
#include<set>
#include<numeric>
#include<iterator>
#include<cmath>
#include<algorithm>
using namespace std;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(v) ((int)v.size())
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define repi(n)  for(int i = 0; i < (int)(n); ++i)
#define repj(n)  for(int j = 0; j < (int)(n); ++j)
#define reprng(i,a,b) for(int i = a; i <= (int)(b); ++i)
#define reprngr(i,n,a) for(int i = n;i >= (int)(a); --i)
#define in(a, b) (string(a).find(b) != string::npos)
#define clr(a, x) memset(a, x, sizeof(a))
#define on(n, j) (((n) & (1 << (j))) != 0)
#define set(n, j) ((n) | (1 << (j)))
#define unset(n, j) ((n) & (~(1 << (j))))
#define toggle(n, j) ((n) ^ (1 << (j)))
#define l_on(n) ((n) & (- (n)))
#define unset_l_on(n) ((n) & ((n) - 1))
#define set_l_off(n) ( (n) | ((n) + 1))
#define pw2(n) ( ((n) & (n - 1)) == 0)
#define setn(n) ((1 << (n)) - 1)
#define unset_l_11(n) ((l_on(n) + (n)) & (~(l_on(l_on(n) + (n)))))
#define set_l_00(n) (~unset_l_11(~n))
#define rem2(a, b) ((a) & (b - 1))
#define fast_scan() (ios_base::sync_with_stdio(false),cin.tie(NULL))
#define mp make_pair
#define pb push_back
#define PI 3.14159265358979323846
#define f first
#define s second
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<bool> vb;
//ifstream in("input.txt");
ofstream out("output.txt");
const ll OO = 0x3f3f3f3f;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pl;
typedef pair<string, int>Psi;
typedef vector<Pi> vpi;
typedef vector<vi> vvi;
bool comp(pair<int, Pi> a, pair<int, Pi> b) { return a.f < b.f; }
int main()
{
	fast_scan();
	int n, k; cin >> n >> k;
	vi t(n); repi(n) cin >> t[i];
	int m = 0;
	vpi res;
	int ans = k;
	repi(k)
	{
		vi::iterator mini = min_element(all(t));
		vi::iterator maxi = max_element(all(t));
		if (*maxi - *mini <= 1) { ans = *maxi - *mini; break; }
		++(*mini); --(*maxi);
		res.pb(mp(maxi - t.begin(), mini - t.begin()));
	}
	cout << ans <<" "<< sz(res) << endl;
	repi(sz(res)) cout << res[i].f + 1 << " "<<res[i].s + 1 << endl;
	getchar(); getchar();
	return 0;
}


#include <bits/stdc++.h>
#define ll          long long int
#define ff          first
#define ss          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define mpll        map<ll,ll>
#define mpii        map<int,int>
#define vi          vector<ll>
#define vvi         vector<vi>
#define INF         1e9
#define bigMod      1000000007
#define pi          acos(-1.00)
#define fastRead    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;

const int MAX =1e6+6;
ll arr[2000005],brr[2000005],crr[2000005];

int MX(ll arr[],ll n)
{
    ll tmp=-1;
    ll m;
    for(int i=1; i<=n; i++)
    {
        if(arr[i]>tmp)
        {
            tmp=arr[i];
            m=i;
        }
    }
    return m;
}
int MN(ll arr[],ll n)
{
    ll tmp=1e9;
    ll nn;
    for(int i=1; i<=n; i++)
    {
        if(arr[i]<tmp)
        {
            tmp=arr[i];
            nn=i;
        }
    }
    return nn;
}

int main()
{
    fastRead;
    ll n,k,ans=1e9;
    cin>>n>>k;
    vector<pii>v;
    for(int i=1; i<=n; i++)
        cin>>arr[i];
    int mn,mx;
    while(k--)
    {
        mx=MX(arr,n);
        mn=MN(arr,n);
        arr[mn]++;
        arr[mx]--;
        if(ans<=abs(arr[MX(arr,n)]-arr[MN(arr,n)]))
            break;
        else
        {
            ans=abs(arr[MX(arr,n)]-arr[MN(arr,n)]);
            v.push_back({mx,mn});
        }
    }
    cout<<arr[MX(arr,n)]-arr[MN(arr,n)]<<" "<<v.size()<<"\n";
    for(int i=0; i<v.size(); i++)
        cout<<v[i].first<<" "<<v[i].second<<"\n";
}


#include <bits/stdc++.h>
#define ll          long long int
#define ff          first
#define ss          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define mpll        map<ll,ll>
#define mpii        map<int,int>
#define vi          vector<ll>
#define vvi         vector<vi>
#define INF         1e9
#define bigMod      1000000007
#define pi          acos(-1.00)
#define fastRead    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;

const int MAX =1e6+6;
ll arr[2000005],brr[2000005],crr[2000005];

int MX(ll arr[],ll n)
{
    ll tmp=-1;
    ll m;
    for(int i=1; i<=n; i++)
    {
        if(arr[i]>tmp)
        {
            tmp=arr[i];
            m=i;
        }
    }
    return m;
}
int MN(ll arr[],ll n)
{
    ll tmp=1e9;
    ll nn;
    for(int i=1; i<=n; i++)
    {
        if(arr[i]<tmp)
        {
            tmp=arr[i];
            nn=i;
        }
    }
    return nn;
}

int main()
{
    fastRead;
    ll n,k,ans=1e9;
    cin>>n>>k;
    vector<pii>v;
    for(int i=1; i<=n; i++)
        cin>>arr[i];
    int mn,mx;
    while(k--)
    {
        mx=MX(arr,n);
        mn=MN(arr,n);
        arr[mn]++;
        arr[mx]--;
        ll itm=arr[MX(arr,n)]-arr[MN(arr,n)];
        if(ans<=itm||mx==mn)
            break;
        else
        {
            ans=arr[MX(arr,n)]-arr[MN(arr,n)];
            v.push_back({mx,mn});
        }
    }
    cout<<arr[MX(arr,n)]-arr[MN(arr,n)]<<" "<<v.size()<<"\n";
    for(int i=0; i<v.size(); i++)
        cout<<v[i].first<<" "<<v[i].second<<"\n";
}


#include <bits/stdc++.h>
#define ll          long long int
#define ff          first
#define ss          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define mpll        map<ll,ll>
#define mpii        map<int,int>
#define vi          vector<ll>
#define vvi         vector<vi>
#define INF         1e9
#define bigMod      1000000007
#define pi          acos(-1.00)
#define fastRead    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;

const int MAX =1e6+6;
ll arr[2000005],brr[2000005],crr[2000005];

int MX(ll arr[],ll n)
{
    ll tmp=-1;
    ll m;
    for(int i=1; i<=n; i++)
    {
        if(arr[i]>tmp)
        {
            tmp=arr[i];
            m=i;
        }
    }
    return m;
}
int MN(ll arr[],ll n)
{
    ll tmp=1e9;
    ll nn;
    for(int i=1; i<=n; i++)
    {
        if(arr[i]<tmp)
        {
            tmp=arr[i];
            nn=i;
        }
    }
    return nn;
}

int main()
{
    fastRead;
    ll n,k,ans=1e9;
    cin>>n>>k;
    vector<pii>v;
    for(int i=1; i<=n; i++)
        cin>>arr[i];
    int mn,mx;
    while(k--)
    {
        mx=MX(arr,n);
        mn=MN(arr,n);
        arr[mn]++;
        arr[mx]--;
        if(mx==mn)
            break;
        v.push_back({mx,mn});
    }
    cout<<arr[MX(arr,n)]-arr[MN(arr,n)]<<" "<<v.size()<<"\n";
    for(int i=0; i<v.size(); i++)
        cout<<v[i].first<<" "<<v[i].second<<"\n";
}


#include <bits/stdc++.h>
#define ll          long long int
#define ff          first
#define ss          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define mpll        map<ll,ll>
#define mpii        map<int,int>
#define vi          vector<ll>
#define vvi         vector<vi>
#define INF         1e9
#define bigMod      1000000007
#define pi          acos(-1.00)
#define fastRead    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;

const int MAX =1e6+6;
ll arr[2000005],brr[2000005],crr[2000005];

int main()
{
    fastRead;
    ll n,k,ans;
    cin>>n>>k;
    vector<pii>v;
    for(int i=1; i<=n; i++)
        cin>>arr[i];
    while(k--)
    {
        int mx=0;
        for(int i=1; i<=n; i++)
            if(!mx||arr[i]>arr[mx])
                mx=i;
        int mn=0;
        for(int i=1; i<=n; i++)
            if(!mn||arr[i]<arr[mn])
                mn=i;
        if(mx==mn)
        {
            ans=0;
            break;
        }
        arr[mx]--;
        arr[mn]++;
        v.push_back({mx,mn});
    }
    int mx=0;
    for(int i=1; i<=n; i++)
        if(!mx||arr[i]>arr[mx])
            mx=i;
    int mn=0;
    for(int i=1; i<=n; i++)
        if(!mn||arr[i]<arr[mn])
            mn=i;
    ans=arr[mx]-arr[mn];
    cout<<ans<<" "<<v.size()<<endl;
    for(int i=0; i<v.size(); i++)
        cout<<v[i].first<<" "<<v[i].second<<endl;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#include<string.h>
#define pi 3.1415926535897932384626433832795028841971
#define str_max_len 4294967295
#define max_ll LLONG_MAX
#define min_ll LLONG_MIN
#define cps CLOCKS_PER_SEC
#define pb push_back
#define fi first
#define se second
#define in insert
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
ll ll_max(ll a,ll b,ll c){return max(a,max(b,c));}
int int_max(int a,int b,int c){return max(a,max(b,c));}
ll ll_min(ll a,ll b,ll c){return min(a,min(b,c));}
int int_min(int a,int b,int c){return min(a,min(b,c));}
ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);}
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}
ll dx[]={0,0,1,-1};
ll dy[]={1,-1,0,0};
ll power(ll x,ll y,ll m){            //power(x,y)=x^y  %m;
    if(y==0)return 1;
    ll a=power(x,y/2,m);
    if(y%2){
        return (a*((a*x)%m))%m;
    }
    else{
        return (a*a)%m;
    }
}
ll mod_inverse(ll x,ll m){
    return power(x,m-2,m);
}
ll fact(ll n,ll m){
    if(n<=1)return 1;
    return (fact(n-1,m)*n)%m;
}
ll ncr(ll n,ll r,ll m){
    if(r>n)return 0;
    ll n1=1,d1=1,d2=1;
    n1=fact(n,m);d1=fact(r,m);d2=fact(n-r,m);
    ll ans=mod_inverse((d1*d2)%m,m);
    ans=(ans*n1)%m;
    return ans;
}
int gcd(int a, int b){
    if (a < b)return gcd(b, a);
    if (a % b == 0) return b;
    return gcd(b,a % b);}

bool sortbysec(const pair<ll,ll> &a,
              const pair<ll,ll> &b)
{
    return (a.second < b.second);
}

/***************************code begins here*****************************/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	cout<<fixed<<setprecision(15);

	ll n,k;cin>>n>>k;
	ll a[n];fo(i,n)cin>>a[i];
	if(k==1)
	{
		return 0;
	}
	vector <pair<ll,ll>> vec;
	fo(i,n)
	vec.pb(make_pair(a[i],i));
	ll c=0;
	vector <ll> v1,v2;
	while(k--)
	{
		sort(vec.begin(),vec.end());
		if(vec[n-1].fi-vec[0].fi<=1)break;
		vec[0].fi+=1,vec[n-1].fi-=1;
		v1.pb(vec[0].se);v2.pb(vec[n-1].se);
		c++;
	}
	sort(vec.begin(),vec.end());
	cout<<vec[n-1].fi-vec[0].fi<<" "<<c<<endl;
	fo(i,v1.size())
	cout<<v2[i]+1<<" "<<v1[i]+1<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#include<string.h>
#define pi 3.1415926535897932384626433832795028841971
#define str_max_len 4294967295
#define max_ll LLONG_MAX
#define min_ll LLONG_MIN
#define cps CLOCKS_PER_SEC
#define pb push_back
#define fi first
#define se second
#define in insert
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
ll ll_max(ll a,ll b,ll c){return max(a,max(b,c));}
int int_max(int a,int b,int c){return max(a,max(b,c));}
ll ll_min(ll a,ll b,ll c){return min(a,min(b,c));}
int int_min(int a,int b,int c){return min(a,min(b,c));}
ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);}
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}
ll dx[]={0,0,1,-1};
ll dy[]={1,-1,0,0};
ll power(ll x,ll y,ll m){            //power(x,y)=x^y  %m;
    if(y==0)return 1;
    ll a=power(x,y/2,m);
    if(y%2){
        return (a*((a*x)%m))%m;
    }
    else{
        return (a*a)%m;
    }
}
ll mod_inverse(ll x,ll m){
    return power(x,m-2,m);
}
ll fact(ll n,ll m){
    if(n<=1)return 1;
    return (fact(n-1,m)*n)%m;
}
ll ncr(ll n,ll r,ll m){
    if(r>n)return 0;
    ll n1=1,d1=1,d2=1;
    n1=fact(n,m);d1=fact(r,m);d2=fact(n-r,m);
    ll ans=mod_inverse((d1*d2)%m,m);
    ans=(ans*n1)%m;
    return ans;
}
int gcd(int a, int b){
    if (a < b)return gcd(b, a);
    if (a % b == 0) return b;
    return gcd(b,a % b);}

bool sortbysec(const pair<ll,ll> &a,
              const pair<ll,ll> &b)
{
    return (a.second < b.second);
}

/***************************code begins here*****************************/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	cout<<fixed<<setprecision(15);

	ll n,k;cin>>n>>k;
	ll a[n];fo(i,n)cin>>a[i];

	vector <pair<ll,ll>> vec;
	fo(i,n)
	vec.pb(make_pair(a[i],i));
	ll c=0;
	vector <ll> v1,v2;
	while(k--)
	{
		sort(vec.begin(),vec.end());
		if(vec[n-1].fi-vec[0].fi<=1)break;
		vec[0].fi+=1,vec[n-1].fi-=1;
		v1.pb(vec[0].se);v2.pb(vec[n-1].se);
		c++;
	}
	sort(vec.begin(),vec.end());
	cout<<vec[n-1].fi-vec[0].fi<<" "<<c<<endl;
	fo(i,v1.size())
	cout<<v2[i]+1<<" "<<v1[i]+1<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#include<string.h>
#define pi 3.1415926535897932384626433832795028841971
#define str_max_len 4294967295
#define max_ll LLONG_MAX
#define min_ll LLONG_MIN
#define cps CLOCKS_PER_SEC
#define pb push_back
#define fi first
#define se second
#define in insert
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
ll ll_max(ll a,ll b,ll c){return max(a,max(b,c));}
int int_max(int a,int b,int c){return max(a,max(b,c));}
ll ll_min(ll a,ll b,ll c){return min(a,min(b,c));}
int int_min(int a,int b,int c){return min(a,min(b,c));}
ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);}
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}
ll dx[]={0,0,1,-1};
ll dy[]={1,-1,0,0};
ll power(ll x,ll y,ll m){            //power(x,y)=x^y  %m;
    if(y==0)return 1;
    ll a=power(x,y/2,m);
    if(y%2){
        return (a*((a*x)%m))%m;
    }
    else{
        return (a*a)%m;
    }
}
ll mod_inverse(ll x,ll m){
    return power(x,m-2,m);
}
ll fact(ll n,ll m){
    if(n<=1)return 1;
    return (fact(n-1,m)*n)%m;
}
ll ncr(ll n,ll r,ll m){
    if(r>n)return 0;
    ll n1=1,d1=1,d2=1;
    n1=fact(n,m);d1=fact(r,m);d2=fact(n-r,m);
    ll ans=mod_inverse((d1*d2)%m,m);
    ans=(ans*n1)%m;
    return ans;
}
int gcd(int a, int b){
    if (a < b)return gcd(b, a);
    if (a % b == 0) return b;
    return gcd(b,a % b);}

bool sortbysec(const pair<ll,ll> &a,
              const pair<ll,ll> &b)
{
    return (a.second < b.second);
}

/***************************code begins here*****************************/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	cout<<fixed<<setprecision(15);

	ll n,k;cin>>n>>k;
	ll a[n];fo(i,n)cin>>a[i];
	if(k==1)
	{
		return 0;
	}
	vector <pair<ll,ll>> vec;
	fo(i,n)
	vec.pb(make_pair(a[i],i));
	ll c=0;
	vector <ll> v1,v2;
	while(k--)
	{
		sort(vec.begin(),vec.end());
		if(vec[n-1].fi-vec[0].fi<=1)break;
		vec[0].fi+=1,vec[n-1].fi-=1;
		v1.pb(vec[0].se);v2.pb(vec[n-1].se);
		c++;
	}
	sort(vec.begin(),vec.end());
	cout<<vec[n-1].fi-vec[0].fi<<" "<<c<<endl;
	fo(i,v1.size())
	cout<<v1[i]+1<<" "<<v2[i]+1<<endl;
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <set>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#define ll long long
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<pair<int, int> > v;
    for (int i = 0; i < n; i++){
        int a, b;
        scanf("%d%d", &a, &b);
        v.push_back(make_pair(a, b));
    }
    sort(v.begin(), v.end());
    int b = v[0].second;
    int c = 0;
    for (int i = 1; i < n; i++){
        if (v[i].first < b && v[i].second < b){
            c++;
        }
        else b = v[i].second;
    }
    cout << c;
    //system("pause");
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <set>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#define ll long long
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<pair<int, int> > v;
    for (int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        v.push_back(make_pair(a, b));
    }
    sort(v.begin(), v.end());
    int b = v[0].second;
    int c = 0;
    for (int i = 1; i < n; i++){
        if (v[i].first < b && v[i].second < b){
            c++;
        }
        else b = v[i].second;
    }
    cout << c;
    //system("pause");
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	//freopen ("input.txt","r",stdin);
	int n;
	cin >> n;
	vector<pair<int,int> > v;
	v.resize(n);
	for (int i = 0; i < n; i++)
		scanf ("%d %d",&v[i].first,&v[i].second);

	sort (v.begin(),v.end());
	int ans = 0;
	int mx = v[0].second;
	for (int i = 1; i < v.size(); i++)
	{
		if (v[i].second < mx)
			ans++;
		mx = max (mx,v[i].second);
	}
	cout << ans;
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
bool p(const pair<int,int> &a,const pair<int,int> &b)
{
	if (a.first < b.first && a.second > b.second)
		return true;
	return false;
}
int main()
{
	//freopen ("input.txt","r",stdin);
	int n;
	cin >> n;
	vector<pair<int,int> > v;
	v.resize(n);
	for (int i = 0; i < n; i++)
		scanf ("%d %d",&v[i].first,&v[i].second);

	sort (v.begin(),v.end());
	int ans = 0;
	int mx = v[0].second;
	for (int i = 1; i < v.size(); i++)
	{
		if (v[i].second < mx)
			ans++;
		mx = max (mx,v[0].second);
	}
	cout << ans;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <conio.h>
#include <utility>
#include <set>
#include <time.h>
#include <list>
#include <typeinfo>
#include <cstdio>
#include <numeric>
#include <limits>
#include <functional>
using namespace std;
#define X first
#define Y second
#define PI 3.1415926535897932384626433832795
#define PI2 PI * 2
#define sqr(x) ((x)*(x))
#define all(n) (n).begin(), (n).end()
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef pair<double, double> pdd;
typedef vector<pdd> vpdd;
typedef pair<float, float> pff;
const int MOD = (int)1e9 + 7;
typedef double real;

void load(int k = 1) {
	if (k == 1)	{
#ifndef ONLINE_JUDGE
		freopen("in", "r", stdin);
		freopen("out", "w", stdout);
#endif
	} else {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
}

const int N = (int)1e5 + 10;
const int M = 100;
int A[N][3];

void solve() {
	int n, res = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d %d", &A[i][0], &A[i][1]);
		A[i][2] = 1;
	}
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			if (A[i][2] && A[i][0] > A[j][0] && A[i][1] < A[j][1]) {
				++res;
				A[i][2] = 0;
			}
			if (A[j][2] && A[i][0] < A[j][0] && A[i][1] > A[j][1]) {
				++res;
				A[j][2] = 0;
			}
			//res += (A[i][0] > A[j][0] && A[i][1] < A[j][1]) || (A[i][0] < A[j][0] && A[i][1] > A[j][1]);
		}
	}
	cout << res;
}

void solve2() {

}

#define TIME_CHECK

int main() {
#ifndef ONLINE_JUDGE
#ifdef TIME_CHECK
	double c1 = clock();
#endif
#endif

	load();
	solve();

#ifndef ONLINE_JUDGE
#ifdef TIME_CHECK
	double c2 = clock();
	cout << endl << "time: " << (c2 - c1) / (CLOCKS_PER_SEC / 1000);
#endif
#endif
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <conio.h>
#include <utility>
#include <set>
#include <time.h>
#include <list>
#include <typeinfo>
#include <cstdio>
#include <numeric>
#include <limits>
#include <functional>
using namespace std;
#define X first
#define Y second
#define PI 3.1415926535897932384626433832795
#define PI2 PI * 2
#define sqr(x) ((x)*(x))
#define all(n) (n).begin(), (n).end()
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef pair<double, double> pdd;
typedef vector<pdd> vpdd;
typedef pair<float, float> pff;
const int MOD = (int)1e9 + 7;
typedef double real;

void load(int k = 1) {
	if (k == 1)	{
#ifndef ONLINE_JUDGE
		freopen("in", "r", stdin);
		freopen("out", "w", stdout);
#endif
	} else {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
}

const int N = (int)1e5 + 10;
const int M = 100;
pair<int, int> A[N];

void solve() {
	int n, res = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d %d", &A[i].X, &A[i].Y);
	}
	sort(A, A + n);
	int g = A[0].Y;
	for (int i = 0; i < n; ++i) {
		if (A[i].Y < g) {
			++res;
		}
		g = max(A[i].Y, g);
	}
	cout << res;
}

void solve2() {

}

#define TIME_CHECK

int main() {
#ifndef ONLINE_JUDGE
#ifdef TIME_CHECK
	double c1 = clock();
#endif
#endif

	load();
	solve();

#ifndef ONLINE_JUDGE
#ifdef TIME_CHECK
	double c2 = clock();
	cout << endl << "time: " << (c2 - c1) / (CLOCKS_PER_SEC / 1000);
#endif
#endif
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <conio.h>
#include <utility>
#include <set>
#include <time.h>
#include <list>
#include <typeinfo>
#include <cstdio>
#include <numeric>
#include <limits>
#include <functional>
using namespace std;
#define X first
#define Y second
#define PI 3.1415926535897932384626433832795
#define PI2 PI * 2
#define sqr(x) ((x)*(x))
#define all(n) (n).begin(), (n).end()
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef pair<double, double> pdd;
typedef vector<pdd> vpdd;
typedef pair<float, float> pff;
const int MOD = (int)1e9 + 7;
typedef double real;

void load(int k = 1) {
	if (k == 1)	{
#ifndef ONLINE_JUDGE
		freopen("in", "r", stdin);
		freopen("out", "w", stdout);
#endif
	} else {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
}

const int N = (int)1e5 + 10;
const int M = 100;
int A[N][2];

void solve() {
	int n, res = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d %d", &A[i][0], &A[i][1]);
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (i == j) continue;
			if (A[i][0] > A[j][0] && A[i][1] < A[j][1]) {
				++res; break;
			}
		}
	}
	cout << res;
}

void solve2() {

}

#define TIME_CHECK

int main() {
#ifndef ONLINE_JUDGE
#ifdef TIME_CHECK
	double c1 = clock();
#endif
#endif

	load();
	solve();

#ifndef ONLINE_JUDGE
#ifdef TIME_CHECK
	double c2 = clock();
	cout << endl << "time: " << (c2 - c1) / (CLOCKS_PER_SEC / 1000);
#endif
#endif
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

struct ev {
	int end;
	int start;
	bool operator<(ev b) {
		return start < b.start;
	}
};

ev evs[100000];

int main() {
	int n;
	cin >> n;
	int a, b;
	int le = 0;
	int ans = 0;
	for(int i = 0 ; i < n; i++) {
		cin >> a >> b;
		evs[i].end = b;
		evs[i].start = a;
	}
	sort(evs, evs+n);
	int maxrange = evs[0].end;
	for(int i = 1; i < n; i++) {
		if (evs[i].end > maxrange) {
			maxrange = evs[i].end;
		} else {
			//maxrange = max(evs[i].end, maxrange);
			ans++;
		}
	}
	cout << ans;
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

struct ev {
	int end;
	int start;
	bool operator<(ev b) {
		return start < b.start;
	}
};

ev evs[100000];

int main() {
	int n;
	cin >> n;
	int a, b;
	int le = 0;
	int ans = 0;
	for(int i = 0 ; i < n; i++) {
		cin >> a >> b;
		evs[i].end = b;
		evs[i].start = a;
	}
	sort(evs, evs+n);
	int maxrange = evs[0].end;
	for(int i = 1; i < n; i++) {
		if (evs[i].start > maxrange) {
			maxrange = evs[i].end;
		} else {
			maxrange = max(evs[i].end, maxrange);
			ans++;
		}
	}
	cout << ans;
	return 0;
}


#include<iostream>
using namespace std;
void main()
{
    int year[100000][2];
        int n,sum=0,c=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>year[i][0]>>year[i][1];
        if(year[i][0]+year[i][1]>sum)
            sum=year[i][0]+year[i][1];
    }
    if(n>1)
    {
    for(int i=1;i<n;i++)
        if(year[i][0]+year[i][1]<=sum)
            c++;
    cout<<"\n"<<c;
    }
    else
        cout<<"\n"<<0;
}


#include<iostream>
#include<algorithm>
#include<utility>
using namespace std;
void main()
{
    pair<int,int> dates[100001];
    int n;
    cin>>n;
    for (int i = 0; i < n; i++)
    cin>>dates[i].first>>dates[i].second;
    sort(dates,dates+n);
    int rg=-1,res=0;
    for (int i = 0; i < n; i++)
    {
        if(rg<dates[i].second)
            rg=dates[i].second;
        else
            res++;
    }
    cout<<"\n"<<res;
}


#include<iostream>
#include<algorithm>
#include<utility>
using namespace std;
void main()
{
	pair<int,int> dates[100001];
	int n;
	cin>>n;
	for (int i = 0; i < n; i++)
	cin>>dates[i].first>>dates[i].second;
	sort(dates,dates+n);
	int rg=-1,res=0;
	for (int i = 0; i < n; i++)
	{
		if(rg>dates[i].second)
			rg=dates[i].second;
		else
			res++;
	}
	cout<<"\n"<<res;
}


#pragma warning( disable : 4996)
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:666000000")

#define bublic public

#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <time.h>
#include <vector>
#include <stack>

#define nextLine() {for(int c=getchar(); c!='\n' && c!=EOF; c=getchar());}
#define sqr(a) ((a)*(a))
#define has(mask,i) (((mask) & (1<<(i))) == 0 ? false : true)
#define set_true(mask, i) (mask|(1<<(i)))
#define set_false(mask, i) (~((~mask)|(1<<(i))))
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

#define TASK "file"

using namespace std;

#ifndef ONLINE_JUDGE
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define parr(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";puts("");}puts("");
#define log(x) cerr << #x << " = " << x << endl
#else
#define eprintf(...)
#define parr(a,n,m)
#define log(x)
#endif

#define mp(x, y) make_pair(x, y)
#define pb(_o_) push_back(_o_)

typedef long long LL;
typedef unsigned long long ULL;
typedef long double ldb;

typedef pair<int,int> pii;
typedef pair<pii,int> tiii;
typedef pair<pii,pii> fiiii;
#define FI first.first
#define SE first.second
#define TH second.first
#define FO second.second

#define FORN(i,n) for(int i = 0; i < (int)n; i++)
#define FORR(i,n) for(int i = n - 1; i >= 0; i--)
#define FORS(it,a) for(auto it = a.begin(); it != a.end(); it++)

typedef vector<int> vi;
typedef vector<vi> vvi;

#ifndef ONLINE_JUDGE
typedef vector<int> vc;
typedef vector<vc> vvc;
#else
typedef vector<char> vc;
typedef vector<char> vvc;
#endif

const int INF = (1 << 30) - 1;
const ldb EPS = 1e-9;

void ML(const bool v)
{
    if (v)
        return;
    int *ass;
    for (;;)
    {
        ass = new int[2500000];
        for (int i = 0; i < 2500000; i++)
            ass[i] = rand();
    }
}

void TL(const bool v)
{
    if (v)
        return;
    for (;;)
        cout << rand() % (rand() % 1000) << endl;
}

void PE(const bool v)
{
    if (v)
        return;
    for (int i = 0; i < 10000; i++)
        printf("%c", rand() % 256);
    exit(0);
}

int n;
vector<pii> a;

void LoAd()
{
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n;  i++)
        scanf("%d%d", &a[i].first, &a[i].second);
}

void SoLvE()
{
    sort(a.begin(), a.end());
    pii tt;
    int res = 0;
    for (int i = 0; i < n; i++)
    {
        if (i == 0 || a[i].second >= tt.second)
            tt = a[i];
        else
            res++;
    }

    cout << res << endl;
}

int main()
{
    srand( (int) time(NULL));
#ifndef ONLINE_JUDGE
    freopen(TASK".in","r",stdin);   freopen(TASK".out","w",stdout);
#endif
    LoAd();
    SoLvE();
    return 0;
}


#pragma warning( disable : 4996)
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:666000000")

#define bublic public

#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <time.h>
#include <vector>
#include <stack>

#define nextLine() {for(int c=getchar(); c!='\n' && c!=EOF; c=getchar());}
#define sqr(a) ((a)*(a))
#define has(mask,i) (((mask) & (1<<(i))) == 0 ? false : true)
#define set_true(mask, i) (mask|(1<<(i)))
#define set_false(mask, i) (~((~mask)|(1<<(i))))
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

#define TASK "file"

using namespace std;

#ifndef ONLINE_JUDGE
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define parr(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";puts("");}puts("");
#define log(x) cerr << #x << " = " << x << endl
#else
#define eprintf(...)
#define parr(a,n,m)
#define log(x)
#endif

#define mp(x, y) make_pair(x, y)
#define pb(_o_) push_back(_o_)

typedef long long LL;
typedef unsigned long long ULL;
typedef long double ldb;

typedef pair<int,int> pii;
typedef pair<pii,int> tiii;
typedef pair<pii,pii> fiiii;
#define FI first.first
#define SE first.second
#define TH second.first
#define FO second.second

#define FORN(i,n) for(int i = 0; i < (int)n; i++)
#define FORR(i,n) for(int i = n - 1; i >= 0; i--)
#define FORS(it,a) for(auto it = a.begin(); it != a.end(); it++)

typedef vector<int> vi;
typedef vector<vi> vvi;

#ifndef ONLINE_JUDGE
typedef vector<int> vc;
typedef vector<vc> vvc;
#else
typedef vector<char> vc;
typedef vector<char> vvc;
#endif

const int INF = (1 << 30) - 1;
const ldb EPS = 1e-9;

void ML(const bool v)
{
    if (v)
        return;
    int *ass;
    for (;;)
    {
        ass = new int[2500000];
        for (int i = 0; i < 2500000; i++)
            ass[i] = rand();
    }
}

void TL(const bool v)
{
    if (v)
        return;
    for (;;)
        cout << rand() % (rand() % 1000) << endl;
}

void PE(const bool v)
{
    if (v)
        return;
    for (int i = 0; i < 10000; i++)
        printf("%c", rand() % 256);
    exit(0);
}

int n;
vector<pii> a;

void LoAd()
{
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n;  i++)
        scanf("%d%d", &a[i].first, &a[i].second);
}

vi yr;
map<int, int> encode;

#define left(v) (v*2)
#define rigt(v) (v*2+1)

struct
{
    struct node
    {
        int lt, rt, wt, mx;
        bool leaf()
        {
            return lt == rt;
        }
        int val()
        {
            return mx + wt;
        }
    };
    static const int BT = 17;
    static const int SZ = (1<<BT);
    node a[2*SZ];
    void init(const int v, const int lt, const int rt)
    {
        a[v].lt = lt;
        a[v].rt = rt;
        a[v].wt = 0;
        a[v].mx = 0;
        if (!a[v].leaf())
        {
            init(left(v), lt, (lt + rt) / 2);
            init(rigt(v), 1 + (lt + rt) / 2, rt);
        }
    }
    void init()
    {
        init(1, 0, SZ - 1);
    }
    void push(const int v)
    {
        a[v].mx += a[v].wt;
        if (!a[v].leaf())
        {
            a[left(v)].wt += a[v].wt;
            a[rigt(v)].wt += a[v].wt;
        }
        a[v].wt = 0;
    }
    void add(const int v, const int lt, const int rt)
    {
        if (lt <= a[v].lt && a[v].rt <= rt)
        {
            a[v].wt++;
            return;
        }
        if (lt > a[v].rt || rt < a[v].lt)
            return;
        push(v);
        add(left(v), lt, rt);
        add(rigt(v), lt, rt);
        a[v].mx = min(a[left(v)].val(), a[rigt(v)].val());
    }
    int get(const int v, const int lt, const int rt)
    {
        if (lt <= a[v].lt && a[v].rt <= rt)
            return a[v].val();
        if (lt > a[v].rt || rt < a[v].lt)
            return INF;
        push(v);
        return min(get(left(v), lt, rt), get(rigt(v), lt, rt));
    }
} sgt;

void SoLvE()
{
    for (int i = 0; i < n; i++)
    {
        yr.push_back(a[i].first);
        yr.push_back(a[i].second);
    }
    sort(yr.begin(), yr.end());
    yr.erase(unique(yr.begin(), yr.end()), yr.end());
    for (int i = 0; i < (int) yr.size(); i++)
    {
        encode[yr[i]] = i + 1;
    }

    for (int i = 0; i < n; i++)
    {
        a[i].first = encode[a[i].first];
        a[i].second = encode[a[i].second];
    }
    sgt.init();
    LL res = 0;
    for (int i = 0; i < n; i++)
    {
        res += min(1, sgt.get(1, a[i].first - 1, a[i].second + 1));
        sgt.add(1, a[i].first, a[i].second);
    }
    cout << res << endl;
}

int main()
{
    srand( (int) time(NULL));
#ifndef ONLINE_JUDGE
    freopen(TASK".in","r",stdin);   freopen(TASK".out","w",stdout);
#endif
    LoAd();
    SoLvE();
    return 0;
}


#pragma warning( disable : 4996)
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:666000000")

#define bublic public

#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <time.h>
#include <vector>
#include <stack>

#define nextLine() {for(int c=getchar(); c!='\n' && c!=EOF; c=getchar());}
#define sqr(a) ((a)*(a))
#define has(mask,i) (((mask) & (1<<(i))) == 0 ? false : true)
#define set_true(mask, i) (mask|(1<<(i)))
#define set_false(mask, i) (~((~mask)|(1<<(i))))
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

#define TASK "file"

using namespace std;

#ifndef ONLINE_JUDGE
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define parr(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";puts("");}puts("");
#define log(x) cerr << #x << " = " << x << endl
#else
#define eprintf(...)
#define parr(a,n,m)
#define log(x)
#endif

#define mp(x, y) make_pair(x, y)
#define pb(_o_) push_back(_o_)

typedef long long LL;
typedef unsigned long long ULL;
typedef long double ldb;

typedef pair<int,int> pii;
typedef pair<pii,int> tiii;
typedef pair<pii,pii> fiiii;
#define FI first.first
#define SE first.second
#define TH second.first
#define FO second.second

#define FORN(i,n) for(int i = 0; i < (int)n; i++)
#define FORR(i,n) for(int i = n - 1; i >= 0; i--)
#define FORS(it,a) for(auto it = a.begin(); it != a.end(); it++)

typedef vector<int> vi;
typedef vector<vi> vvi;

#ifndef ONLINE_JUDGE
typedef vector<int> vc;
typedef vector<vc> vvc;
#else
typedef vector<char> vc;
typedef vector<char> vvc;
#endif

const int INF = (1 << 30) - 1;
const ldb EPS = 1e-9;

void ML(const bool v)
{
    if (v)
        return;
    int *ass;
    for (;;)
    {
        ass = new int[2500000];
        for (int i = 0; i < 2500000; i++)
            ass[i] = rand();
    }
}

void TL(const bool v)
{
    if (v)
        return;
    for (;;)
        cout << rand() % (rand() % 1000) << endl;
}

void PE(const bool v)
{
    if (v)
        return;
    for (int i = 0; i < 10000; i++)
        printf("%c", rand() % 256);
    exit(0);
}

int n;
vector<pii> a;

void LoAd()
{
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n;  i++)
        scanf("%d%d", &a[i].first, &a[i].second);
}

void SoLvE()
{
    pii tt;
    int res = 0;
    for (int i = 0; i < n; i++)
    {
        if (i == 0 || a[i].second >= tt.second)
            tt = a[i];
        else
            res++;
    }

    cout << res << endl;
}

int main()
{
    srand( (int) time(NULL));
#ifndef ONLINE_JUDGE
    freopen(TASK".in","r",stdin);   freopen(TASK".out","w",stdout);
#endif
    LoAd();
    SoLvE();
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
struct node
{
    ll a, b;
    bool flag;
}no[100002];
bool cmp(node p, node q)
{
    return p.a < q.a;
}
int main()
{
    int n, i,j;
    cin >> n;
    for (i = 0; i < n; ++i)
    {
        cin >> no[i].a >> no[i].b;
        no[i].flag = 0;
    }
    if (n==1)
    {
        cout << 0 << endl;
        return 0;
    }
    sort(no,no+n,cmp);
    ll ans = 0;
    for (i = 0; i < n-1; ++i)
    {
        for (j = i + 1; j < n; ++j)
        {
            if (no[i].b > no[j].b&&no[j].flag == 0)
            {
                ans++;
                no[j].flag = 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
struct node
{
    ll a, b;
    bool flag;
};
vector<node> v;
bool cmp(node p, node q)
{
    return p.a < q.a;
}
int main()
{
    int n, i,j;
    cin >> n;
    node tmp;
    ll ta, tb;
    for (i = 0; i < n; ++i)
    {
        cin >> ta >> tb;
        tmp.a = ta;
        tmp.b = tb;
        tmp.flag = 0;
        v.push_back(tmp);
    }
    if (n==1)
    {
        cout << 0 << endl;
        return 0;
    }
    sort(v.begin(), v.end(),cmp);
    /*for (i = 0; i < n; ++i)
        cout << v[i].a << " " << v[i].b << endl;*/
    ll ans = 0;
    for (i = 0; i < n-1; ++i)
    {
        for (j = i + 1; j < n&&v[j].flag == 0; ++j)
        {
            if (v[i].b>v[j].b&&v[j].flag == 0)
            {
                ans++;
                v[j].flag = 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
struct node
{
    ll a, b;
    bool flag;
};
vector<node> v;
bool cmp(node p, node q)
{
    return p.a < q.a || (p.a == q.a&&p.b < q.b);
}
int main()
{
    int n, i,j;
    cin >> n;
    node tmp;
    ll ta, tb;
    for (i = 0; i < n; ++i)
    {
        cin >> ta >> tb;
        tmp.a = ta;
        tmp.b = tb;
        tmp.flag = 0;
        v.push_back(tmp);
    }
    if (n==1)
    {
        cout << 0 << endl;
        return 0;
    }
    sort(v.begin(), v.end(),cmp);
    ll ans = 0;
    for (i = 0; i < n; ++i)
    {
        for (j = i + 1; j < n&&v[j].flag == 0; ++j)
        {
            if (v[i].a<v[j].a&&v[i].b>v[j].b&&v[j].flag == 0)
            {
                ans++;
                v[j].flag = 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
struct node
{
    ll a, b;
    bool flag;
};
vector<node> v;
bool cmp(node p, node q)
{
    return p.a < q.a;
}
int main()
{
    int n, i,j;
    cin >> n;
    node tmp;
    ll ta, tb;
    for (i = 0; i < n; ++i)
    {
        cin >> ta >> tb;
        tmp.a = ta;
        tmp.b = tb;
        tmp.flag = 0;
        v.push_back(tmp);
    }
    if (n==1)
    {
        cout << 0 << endl;
        return 0;
    }
    sort(v.begin(), v.end(),cmp);
    /*for (i = 0; i < n; ++i)
        cout << v[i].a << " " << v[i].b << endl;*/
    ll ans = 0;
    for (i = 0; i < n-1; ++i)
    {
        for (j = i + 1; j < n; ++j)
        {
            if (v[i].b>v[j].b&&v[j].flag == 0)
            {
                ans++;
                v[j].flag = 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
struct node
{
    ll a, b;
    int flag;
}no[100002];
bool cmp(node p, node q)
{
    return p.a < q.a;
}
int main()
{
    int n, i,j;
    cin >> n;
    for (i = 0; i < n; ++i)
    {
        cin >> no[i].a >> no[i].b;
        no[i].flag = 0;
    }
    if (n==1)
    {
        cout << 0 << endl;
        return 0;
    }
    sort(no,no+n,cmp);
    ll ans = 0;
    for (i = 0; i < n-1; ++i)
    {
        for (j = i + 1; j < n; ++j)
        {
            if (no[i].b > no[j].b)
            {
                ans++;
                no[j].flag ++;
            }
        }
    }
    for (i = 0; i < n; ++i)
    {
        if (no[i].flag != 0 && no[i].flag != 1)
            ans -= no[i].flag - 1;
    }
    cout << ans << endl;
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
    int n, i;
    pair <int, int> a[100010];
    cin >> n;
    for (i = 1; i <= n;++i)
        cin >> a[i].first >> a[i].second;
    sort(a + 1, a + n + 1);
    int x = a[1].second, res = 0;
    for (i = 2; i <= n;++i)
        if (a[i].second<x)
            res++;
        else
            x = a[i].second;
    cout << res << endl;
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
struct node
{
    ll a, b;
    bool flag;
};
vector<node> v;
bool cmp(node p, node q)
{
    return p.a < q.a;
}
int main()
{
    int n, i,j;
    cin >> n;
    node tmp;
    ll ta, tb;
    for (i = 0; i < n; ++i)
    {
        cin >> ta >> tb;
        tmp.a = ta;
        tmp.b = tb;
        tmp.flag = 0;
        v.push_back(tmp);
    }
    if (n==1)
    {
        cout << 0 << endl;
        return 0;
    }
    sort(v.begin(), v.end(),cmp);
    /*for (i = 0; i < n; ++i)
        cout << v[i].a << " " << v[i].b << endl;*/
    ll ans = 0;
    for (i = 0; i < n-1; ++i)
    {
        for (j = i + 1; j < n&&v[j].flag == 0; ++j)
        {
            if (v[i].b>v[j].b)
            {
                ans++;
                v[j].flag = 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
struct node
{
    ll a, b;
    bool flag = 0;
};
vector<node> v;
bool cmp(node p, node q)
{
    return p.a < q.a || (p.a == q.a&&p.b < q.b);
}
int main()
{
    int n, i,j;
    cin >> n;
    node tmp;
    ll ta, tb;
    for (i = 0; i < n; ++i)
    {
        cin >> ta >> tb;
        tmp.a = ta;
        tmp.b = tb;
        v.push_back(tmp);
    }
    if (n==1)
    {
        cout << 0 << endl;
        return 0;
    }
    sort(v.begin(), v.end(),cmp);
    ll ans = 0;
    for (i = 0; i < n; ++i)
    {
        for (j = i + 1; j < n&&v[j].flag == 0; ++j)
        {
            if (v[i].a<v[j].a&&v[i].b>v[j].b&&v[j].flag == 0)
            {
                ans++;
                v[j].flag = 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
struct node
{
    ll a, b;
    int flag = 0;
};
vector<node> v;
bool cmp(node p, node q)
{
    return p.a < q.a || (p.a == q.a&&p.b < q.b);
}
int main()
{
    int n, i,j;
    cin >> n;
    node tmp;
    ll ta, tb;
    for (i = 0; i < n; ++i)
    {
        cin >> ta >> tb;
        tmp.a = ta;
        tmp.b = tb;
        v.push_back(tmp);
    }
    if (n==1)
    {
        cout << 0 << endl;
        return 0;
    }
    sort(v.begin(), v.end(),cmp);
    ll ans = 0;
    for (i = 0; i < n; ++i)
    {
        for (j = i + 1; j < n&&v[j].flag == 0; ++j)
        {
            if (v[i].a<v[j].a&&v[i].b>v[j].b&&v[j].flag == 0)
            {
                ans++;
                v[j].flag = 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
struct node
{
    ll a, b;
    bool flag;
};
vector<node> v;
bool cmp(node p, node q)
{
    return p.a < q.a;
}
int main()
{
    int n, i,j;
    cin >> n;
    node tmp;
    ll ta, tb;
    for (i = 0; i < n; ++i)
    {
        cin >> ta >> tb;
        tmp.a = ta;
        tmp.b = tb;
        tmp.flag = 0;
        v.push_back(tmp);
    }
    if (n==1)
    {
        cout << 0 << endl;
        return 0;
    }
    sort(v.begin(), v.end(),cmp);
    ll ans = 0;
    for (i = 0; i < n-1; ++i)
    {
        for (j = i + 1; j < n; ++j)
        {
            if (v[j].flag == 0)
            {
                if (v[i].b > v[j].b)
                {
                    ans++;
                    v[j].flag = 1;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <string>
#include <string.h>

using namespace std;
#pragma comment(linker, "/STACK:196777216")

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif

	int c=0, p=0;
	int i, j, k, n, ans=0;
	vector<int> v, b;
	vector<pair<int,int>> a, zb;
	vector<bool> vb;

	cin >> n;
	a.assign(n,make_pair(0,0));
	b.assign(n,0);
	zb.assign(n,make_pair(0,0));
	for (i=0; i<n; i++)
	{
		cin >> j >> k;
		a[i] = make_pair(j, i);
		b[i] = k;
		zb[i] = make_pair(k, i);
	}

	sort(a.begin(), a.end());
	sort(zb.begin() , zb.end());
	//reverse(zb.begin(), zb.end());

	for (i =0; i<a.size(); i++)
	{
		int t = b[a[i].second];

		int l, r, m;
		l = -1;
		r = n;
		while (r-l > 1)
		{
			m = (r+l)/2;
			if ( zb[m].first > t)
				r = m;
			else l = m;
		}
		if (r != n)
		{
			if (zb[r].first != t)
				ans++;
		}
	}

	cout << ans;
	return 0;
}


#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <string>
#include <string.h>

using namespace std;
#pragma comment(linker, "/STACK:196777216")

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif

	int c=0, p=0;
	int i, j, k, n, ans=0;
	vector<int> v, a,b;
	vector<pair<int,int>> za, zb;
	vector<bool> vb;

	cin >> n;
	a.assign(n,0);
	za.assign(n,make_pair(0,0));
	b.assign(n,0);
	zb.assign(n,make_pair(0,0));
	for (i=0; i<n; i++)
	{
		cin >> j >> k;
		a[i] = j;
		za[i] = make_pair(j, i);
		b[i] = k;
		zb[i] = make_pair(k, i);
	}

	sort(za.begin(), za.end());
	//sort(zb.begin() , zb.end());
	//reverse(zb.begin(), zb.end());

	int mx = -1;
	for (i=0; i<za.size(); i++)
	{
		if (mx > b[za[i].second]) ans++;
		else mx = b[za[i].second];
	}

	/*
	for (i =0; i<a.size(); i++)
	{
		int t = b[za[i].second];

		int l, r, m;
		l = -1;
		r = n;
		while (r-l > 1)
		{
			m = (r+l)/2;
			if ( zb[m].first > t)
				r = m;
			else l = m;
		}
		if (r != n)
		{
			if (zb[r].first != t)
				ans++;
		}
	}
	*/
	cout << ans;
	return 0;
}


#include <set>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef pair <int, int> pint;

bool Compare(pint a, pint b) {
    if(a.first != b.first) return a.first < b.first;
    return a.second > b.second;
}

int mxLen[100000 + 10];

int main(void)
{
    int n; cin >> n;

    vector <pint> v;

    for(int i = 0; i < n; i++) {
        int a, b; cin >> a >> b;
        v.push_back(make_pair(a, b));
    }

    sort(v.begin(), v.end());

    mxLen[0] = v[0].second;

    for(int i = 1; i < n; i++) {
        mxLen[i] = max(mxLen[i - 1], v[i].second);
    }

    int K = n - 2, cnt = 0;
    for(int i = n - 1; i > 0; i--) {
        K = min(K, i - 1);
        while(K >= 0 && v[K].first == v[i].first) K--;
        if(K < 0) break;
        if(v[i].second < mxLen[K]) cnt++;
    }

    cout << cnt << endl;

    return 0;
}


// Codeforces 137C History
#include <iostream>
#include <algorithm>
using namespace std;
struct point
{
	int a,b;
}p[100005];
int cmp (point p1,point p2)
{
	return p1.a<p2.a;
}
int main()
{
	int n,i,j,sum;
	while(cin>>n){
		for(i=0;i<n;i++)cin>>p[i].a>>p[i].b;
		sort(p,p+n,cmp);
		for(i=1,sum=0;i<n;i++){
			for(j=i-1;j>=0;j--){
				if(p[i].b<p[j].b){
					sum++;
					break;
				}
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}


// Codeforces 137C History
#include <iostream>
#include <algorithm>
using namespace std;
struct point
{
	int a,b;
}p[100005];
int cmp (point p1,point p2)
{
	return p1.a<p2.a;
}
int main()
{
	int n,i,j,sum;
	while(cin>>n){
		for(i=0;i<n;i++)cin>>p[i].a>>p[i].b;
		sort(p,p+n,cmp);
		for(i=1,sum=0;i<n;i++){
			for(j=0;j<i;j++){
				if(p[i].b<p[j].b){
					sum++;
					break;
				}
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}


// Codeforces 137C History
#include <iostream>
#include <algorithm>
using namespace std;
struct point
{
	int a,b;
}p[100005];
int cmp (point p1,point p2)
{
	return p1.a<p2.a;
}
int main()
{
	int n,i,sum,maxb;
	while(cin>>n){
		for(i=0;i<n;i++)cin>>p[i].a>>p[i].b;
		sort(p,p+n,cmp);
		for(i=1,sum=0,maxb=p[0].b;i<n;i++){
			if(p[i].b>maxb)maxb=p[i].b;
			else sum++;
		}
		cout<<sum<<endl;
	}
	return 0;
}


#include <iostream>
#include <cstring>
#define MAXN 100001
using namespace std;

class Data
{
      public:
      long n;
      long list[MAXN];
      int note[MAXN];
      void input();
      void sort(long x,long y);
      void work();
};

void Data::input()
{
     cin>>n;
     for (long i=0;i<n;i++)
         {
         note[i]=i;
         cin>>list[i];
         note[i+n]=i;
         cin>>list[i+n];
         }
};

void Data::sort(long l,long r)
{

          long i=l,j=r,x=list[(l+r)/2];
          while (i<=j)
                {
                while (list[i]<x) i++;
                while (list[j]>x) j--;
                if (i<=j)
                   {
                   long t=list[i];list[i]=list[j];list[j]=t;
                   int temp=note[i];note[i]=note[j];note[j]=temp;
                   i++;j--;
                   }
                }
          if (i<r) sort(i,r);
          if (j>l) sort(l,j);
};

void Data::work()
{
     sort(0,2*n-1);
     long num[MAXN][2];
     memset(num,-1,sizeof(num));
     for (int i=0;i<n*2;i++)
         if (num[note[i]][0]==-1) num[note[i]][0]=i;
            else num[note[i]][1]=i;
     //for (int i=0;i<n;i++)
        // cout<<num[i][0]<<"   "<<num[i][1]<<endl;
     long ans=0;
     long tmp=0;
     bool hash[MAXN];
     memset(hash,0,sizeof(hash));
     for (long i=1;i<n*2;i++)
         {
         if (hash[note[i]])
            if (tmp<num[note[i]][0])ans++;
         hash[note[i]]=1;
         for (;tmp<=i&&num[note[tmp]][1]<=i;tmp++);
         //cout<<tmp<<endl;
         }
     cout<<ans<<endl;
};

int main()
{
    Data tmp;
    tmp.input();
    tmp.work();
    return 0;
}


#include <iostream>
#include <cstring>
#include "ctime"
#include "cstdlib"
#define MAXN 300001
using namespace std;

class Data
{
      public:
      long n;
      long list[MAXN];
      int note[MAXN];
      void input();
      void sort(long x,long y);
      void work();
};

void Data::input()
{
     cin>>n;
     for (long i=0;i<n;i++)
         {
         note[i]=i;
         cin>>list[i];
         note[i+n]=i;
         cin>>list[i+n];
         }
};

void Data::sort(long l,long r)
{
          //srand((unsigned) time (NULL));
          long i=l,j=r,x=list[l+rand()%(r-l+1)];
          while (i<=j)
                {
                while (list[i]<x) i++;
                while (list[j]>x) j--;
                if (i<=j)
                   {
                   long t=list[i];list[i]=list[j];list[j]=t;
                   int temp=note[i];note[i]=note[j];note[j]=temp;
                   i++;j--;
                   }
                }
          if (i<r) sort(i,r);
          if (j>l) sort(l,j);
};

void Data::work()
{
     sort(0,2*n-1);
     long num[MAXN][2];
     memset(num,-1,sizeof(num));
     for (int i=0;i<n*2;i++)
         if (num[note[i]][0]==-1) num[note[i]][0]=i;
            else num[note[i]][1]=i;
     //for (int i=0;i<n;i++)
        // cout<<num[i][0]<<"   "<<num[i][1]<<endl;
     long ans=0;
     long tmp=0;
     bool hash[MAXN];
     memset(hash,0,sizeof(hash));
     for (long i=1;i<n*2;i++)
         {
         if (hash[note[i]])
            if (tmp<num[note[i]][0])ans++;
         hash[note[i]]=1;
         for (;tmp<=i&&num[note[tmp]][1]<=i;tmp++);
         //cout<<tmp<<endl;
         }
     cout<<ans<<endl;
};

int main()
{
    Data tmp;
    tmp.input();
    tmp.work();
    //system("pause");
    return 0;
}


#include <iostream>
#define MAXN 100001
using namespace std;

class Data
{
      public:
      long n;
      long list[MAXN];
      int note[MAXN];
      void input();
      void sort(long x,long y);
      void work();
};

void Data::input()
{
     cin>>n;
     for (long i=0;i<n;i++)
         {
         note[i]=0;
         cin>>list[i];
         note[i+n]=1;
         cin>>list[i+n];
         }
};

void Data::sort(long l,long r)
{

          long i=l,j=r,x=list[(l+r)/2];
          while (i<=j)
                {
                while (list[i]<x) i++;
                while (list[j]>x) j--;
                if (i<=j)
                   {
                   long t=list[i];list[i]=list[j];list[j]=t;
                   int temp=note[i];note[i]=note[j];note[j]=temp;
                   i++;j--;
                   }
                }
          if (i<r) sort(i,r);
          if (j>l) sort(l,j);
};

void Data::work()
{
     sort(0,2*n-1);
     /*for (long i=0;i<2*n;i++)
         cout<<list[i]<<" "<<note[i]<<endl;*/
     long calc[2]={0,0},ans=0;
     for (long i=0;i<2*n;i++)
         if (note[i]==0) calc[0]++;
            else
                {calc[1]++;if (calc[1]<calc[0]) ans++;}
     cout<<ans<<endl;
};

int main()
{
    Data tmp;
    tmp.input();
    tmp.work();
    //system("pause");
    return 0;
}


#include <iostream>
#include <cstring>
#define MAXN 300001
using namespace std;

class Data
{
      public:
      long n;
      long list[MAXN];
      int note[MAXN];
      void input();
      void sort(long x,long y);
      void work();
};

void Data::input()
{
     cin>>n;
     for (long i=0;i<n;i++)
         {
         note[i]=i;
         cin>>list[i];
         note[i+n]=i;
         cin>>list[i+n];
         }
};

void Data::sort(long l,long r)
{

          long i=l,j=r,x=list[(l+r)/2];
          while (i<=j)
                {
                while (list[i]<x) i++;
                while (list[j]>x) j--;
                if (i<=j)
                   {
                   long t=list[i];list[i]=list[j];list[j]=t;
                   int temp=note[i];note[i]=note[j];note[j]=temp;
                   i++;j--;
                   }
                }
          if (i<r) sort(i,r);
          if (j>l) sort(l,j);
};

void Data::work()
{
     sort(0,2*n-1);
     long num[MAXN][2];
     memset(num,-1,sizeof(num));
     for (int i=0;i<n*2;i++)
         if (num[note[i]][0]==-1) num[note[i]][0]=i;
            else num[note[i]][1]=i;
     //for (int i=0;i<n;i++)
        // cout<<num[i][0]<<"   "<<num[i][1]<<endl;
     long ans=0;
     long tmp=0;
     bool hash[MAXN];
     memset(hash,0,sizeof(hash));
     for (long i=1;i<n*2;i++)
         {
         if (hash[note[i]])
            if (tmp<num[note[i]][0])ans++;
         hash[note[i]]=1;
         for (;tmp<=i&&num[note[tmp]][1]<=i;tmp++);
         //cout<<tmp<<endl;
         }
     cout<<ans<<endl;
};

int main()
{
    Data tmp;
    tmp.input();
    tmp.work();
    return 0;
}


/* Author : Prateep  */
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <iterator>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <cassert>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <ctime>
#include <sstream>
#include <fstream>

using namespace std;

#define LET(x,a)        __typeof(a) x(a)
#define IFOR(i,a,b)     for(LET(i,a);i!=(b);++i)
#define EACH(it,v)      IFOR(it,v.begin(),v.end())
#define FOR(i,a,b)      for(int i=(int)(a) ; i < (int)(b);i++)
#define REP(i,n)        FOR(i,0,n)
#define SZ              size()
#define PB              push_back
#define PF              push_front
#define V(x)            vector< x >
#define two(X)          (1<<(X))
#define twoL(X)         (((int64)(1))<<(X))
#define contain(S,X)    (((S)&two(X))!=0)
#define containL(S,X)   (((S)&twoL(X))!=0
#define swap(x,y)       x ^=y ^= x^=y
#define ALL(v)          (v).begin(),(v).end()

const double pi=acos(-1.0);
const double eps=1e-11;
const int INFINITE=0x3f3f3f3f;
template<class T> inline void checkmin(T &a,T b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,T b){if(b>a) a=b;}
template<class T> inline T sqr(T x){return x*x;}
typedef pair<int,int> ipair;
template<class T> inline T lowbit(T n){return (n^(n-1))&n;}
template<class T> inline int countbit(T n){return (n==0)?0:(1+countbit(n&(n-1)));}

typedef long long       ll;
typedef V(int)          VI;
typedef V(VI)           VII;
typedef V(string)       VS;
typedef long long       int64;
typedef long double     LD;
typedef pair<int,int>   PI;

//#define LocalHost
//int num[5001];

set<PI> s;
set<PI>::iterator it;

bool check(PI a)
{
	for(it = s.begin(); it != s.end(); it++) {
		if((*it).first <= a.first && (*it).second >= a.second)
			return true;
	}
	s.insert(a);
	return false;
}

int main()
{
#ifdef LocalHost
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	ios::sync_with_stdio(false);

	int n; cin >> n;

	int res = 0;
	REP(i,n) {
		int a,b; cin >> a >> b;
		res += check(make_pair(a,b)) ? 1 : 0;
	}

	cout << res << endl;
	return 0;

}


/* Author : Prateep  */
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <iterator>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <cassert>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <ctime>
#include <sstream>
#include <fstream>

using namespace std;

#define LET(x,a)        __typeof(a) x(a)
#define IFOR(i,a,b)     for(LET(i,a);i!=(b);++i)
#define EACH(it,v)      IFOR(it,v.begin(),v.end())
#define FOR(i,a,b)      for(int i=(int)(a) ; i < (int)(b);i++)
#define REP(i,n)        FOR(i,0,n)
#define SZ              size()
#define PB              push_back
#define PF              push_front
#define V(x)            vector< x >
#define two(X)          (1<<(X))
#define twoL(X)         (((int64)(1))<<(X))
#define contain(S,X)    (((S)&two(X))!=0)
#define containL(S,X)   (((S)&twoL(X))!=0
#define swap(x,y)       x ^=y ^= x^=y
#define ALL(v)          (v).begin(),(v).end()

const double pi=acos(-1.0);
const double eps=1e-11;
const int INFINITE=0x3f3f3f3f;
template<class T> inline void checkmin(T &a,T b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,T b){if(b>a) a=b;}
template<class T> inline T sqr(T x){return x*x;}
typedef pair<int,int> ipair;
template<class T> inline T lowbit(T n){return (n^(n-1))&n;}
template<class T> inline int countbit(T n){return (n==0)?0:(1+countbit(n&(n-1)));}

typedef long long       ll;
typedef V(int)          VI;
typedef V(VI)           VII;
typedef V(string)       VS;
typedef long long       int64;
typedef long double     LD;
typedef pair<int,int>   PI;

#define LocalHost
//int num[5001];

vector<PI> s;

//bool check(PI a)
//{
//	for(it = s.begin(); it != s.end(); it++) {
//		if((*it).first <= a.first && (*it).second >= a.second)
//			return true;
//	}
//	s.insert(a);
//	return false;
//}
//
//void printSet()
//{
//	for(it = s.begin(); it != s.end(); it++)
//		cout << it->first << ' ' << it->second << endl;
//
//}

int main()
{
#ifdef LocalHost
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	ios::sync_with_stdio(false);

	int n; cin >> n;

	//int res = 0;
	REP(i,n) {
		int a,b; cin >> a >> b;
		s.push_back(make_pair(a,b));
		//res += check(make_pair(a,b)) ? 1 : 0;
	}
	sort(ALL(s));

	int maxm = -1;
	int res = 0;

	REP(i,s.size()) {
		if(s[i].second < maxm)
			res++;
	    checkmax(maxm,s[i].second);
	}

	cout << res << endl;

	return 0;
}


/* Author : Prateep  */
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <iterator>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <cassert>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <ctime>
#include <sstream>
#include <fstream>

using namespace std;

#define LET(x,a)        __typeof(a) x(a)
#define IFOR(i,a,b)     for(LET(i,a);i!=(b);++i)
#define EACH(it,v)      IFOR(it,v.begin(),v.end())
#define FOR(i,a,b)      for(int i=(int)(a) ; i < (int)(b);i++)
#define REP(i,n)        FOR(i,0,n)
#define SZ              size()
#define PB              push_back
#define PF              push_front
#define V(x)            vector< x >
#define two(X)          (1<<(X))
#define twoL(X)         (((int64)(1))<<(X))
#define contain(S,X)    (((S)&two(X))!=0)
#define containL(S,X)   (((S)&twoL(X))!=0
#define swap(x,y)       x ^=y ^= x^=y
#define ALL(v)          (v).begin(),(v).end()

const double pi=acos(-1.0);
const double eps=1e-11;
const int INFINITE=0x3f3f3f3f;
template<class T> inline void checkmin(T &a,T b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,T b){if(b>a) a=b;}
template<class T> inline T sqr(T x){return x*x;}
typedef pair<int,int> ipair;
template<class T> inline T lowbit(T n){return (n^(n-1))&n;}
template<class T> inline int countbit(T n){return (n==0)?0:(1+countbit(n&(n-1)));}

typedef long long       ll;
typedef V(int)          VI;
typedef V(VI)           VII;
typedef V(string)       VS;
typedef long long       int64;
typedef long double     LD;
typedef pair<int,int>   PI;

//#define LocalHost
//int num[5001];

vector<PI> s;

//bool check(PI a)
//{
//	for(it = s.begin(); it != s.end(); it++) {
//		if((*it).first <= a.first && (*it).second >= a.second)
//			return true;
//	}
//	s.insert(a);
//	return false;
//}
//
//void printSet()
//{
//	for(it = s.begin(); it != s.end(); it++)
//		cout << it->first << ' ' << it->second << endl;
//
//}

int main()
{
#ifdef LocalHost
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	ios::sync_with_stdio(false);

	int n; cin >> n;

	//int res = 0;
	REP(i,n) {
		int a,b; cin >> a >> b;
		s.push_back(make_pair(a,b));
		//res += check(make_pair(a,b)) ? 1 : 0;
	}
	sort(ALL(s));

	int maxm = -1;
	int res = 0;

	REP(i,s.size()) {
		if(s[i].second < maxm)
			res++;
	    checkmax(maxm,s[i].second);
	}

	cout << res << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

struct Event {
    int Start;
    int End;
};

bool EventSorter ( const Event& a, const Event& b )
{
    return a.Start < b.Start || ( a.Start == b.Start && a.End > b.End );
}

int main( int argc, char* argv[] )
{
    vector<Event> events;
    int n;
    cin >> n;
    for( int i = 0; i < n; i++ ) {
        Event e;
        cin >> e.Start >> e.End;
        events.push_back( e );
    }
    sort( events.begin(), events.end(), &EventSorter );

    int lastEnd = events[0].End;
    int sum = 0;
    for( int i = 1; i < events.size(); i++ ) {
        if( events[i].End < lastEnd ) {
            sum++;
        }
        lastEnd = max( lastEnd, events[i].End );
    }
    cout << sum;

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

struct Event {
    int Time;
    bool Start;
    int Index;
};

bool EventSorter( const Event& a, const Event& b )
{
    return a.Time < b.Time;
}

int main( int argc, char* argv[] )
{
    vector<Event> events;
    int n;
    cin >> n;
    for( int i = 0; i < n; i++ ) {
        int a;
        int b;
        cin >> a >> b;
        Event ae;
        ae.Time = a;
        ae.Start = true;
        ae.Index = i;
        Event be;
        be.Time = b;
        be.Start = false;
        be.Index = i;
        events.push_back( ae );
        events.push_back( be );
    }

    sort( events.begin(), events.end(), &EventSorter );
    vector<int> stack;
    int res = 0;
    for( int i = 0; i < events.size(); i++ ) {
        const Event& e = events[i];
        if( e.Start ) {
            stack.push_back( e.Index );
        } else {
            vector<int>::iterator findRes = find( stack.begin(), stack.end(), e.Index );
            if( findRes > stack.begin() ) {
                res++;
            }
            stack.erase( findRes );
        }
    }

    cout << res;

    return 0;
}


//#include "stdafx.h"
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

struct segment
{
	int l,r;
};

bool operator < ( const segment &a, const segment &b )
{
	return a.l<b.l;
}

segment s[100000+1];

int main()
{
	int n;
	scanf("%d",&n);
	for (int i=0;i<n;++i) scanf("%d%d",&s[i].l,&s[i].r);
	sort(s,s+n);
	int cnt=0,mr;
	for (int i=0;i<n;++i)
		if (!i) mr=s[i].r;
		else
			s[i].r<mr ? ++cnt : mr=s[i].r;
	printf("%d",cnt);
	return 0;
}


//#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

struct segment
{
	int l,r;
};

bool operator < ( const segment &a, const segment &b )
{
	return a.l<b.l;
}

int main()
{
	#ifndef ONLINE_JUDGE
		ifstream cin ("input.txt");
		ofstream cout ("output.txt");
	#endif
	int n;
	cin>>n;
	vector<segment> s(n);
	for (int i=0;i<n;++i) cin>>s[i].l>>s[i].r;
	sort(s.begin(),s.end());
	int cnt=0,mr;
	for (int i=0;i<n;++i)
		if (!i) mr=s[i].r;
		else
		{
			s[i].r<mr ? ++cnt : mr=s[i].r;
		}
	cout<<cnt;
	return 0;
}


//WA15
#include <stdio.h>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int n, cnt;
struct sob{int a; int b;} s[100005];
set<int> bb;
set<int>::iterator it;

bool my_sort(struct sob x, struct sob y)
{	if(x.a < y.a)
		return true;
	return false;
}

void my_print()
{	int i;
	for(i=0; i<n; ++i)
		printf("%d\t%d\n", s[i].a, s[i].b);
}

int main()
{	int i;

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	for(i=0; i<n; ++i)
		scanf("%d %d", &s[i].a, &s[i].b);
	sort(s, s+n, my_sort);

	//my_print();

	//bb.reserve(n);
	for(i=0; i<n; ++i)
	{
		it = bb.upper_bound(s[i].b);
		if(it == bb.end())
			bb.insert(s[i].b);
		else
		{
			cnt++;
			bb.insert(s[i].b);
		}
	}

	printf("%d", cnt);
	return 0;
}


//WA15
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

int n, cnt;
struct sob{int a; int b;} s[100005];
vector<int> bb;
vector<int>::iterator it;

bool my_sort(struct sob x, struct sob y)
{	if(x.a < y.a)
		return true;
	return false;
}

void my_print()
{	int i;
	for(i=0; i<n; ++i)
		printf("%d\t%d\n", s[i].a, s[i].b);
}

int main()
{	int i;

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	for(i=0; i<n; ++i)
		scanf("%d %d", &s[i].a, &s[i].b);
	sort(s, s+n, my_sort);

	//my_print();

	bb.reserve(n);
	for(i=0; i<n; ++i)
	{
		it = upper_bound(bb.begin(), bb.end(), s[i].b);
		if(it == bb.end())
			bb.push_back(s[i].b);
		else
		{
			cnt++;
			bb.insert(it, s[i].b);
		}
	}

	printf("%d", cnt);
	return 0;
}


#include <stdio.h>
#include <algorithm>
using namespace std;

int n, cnt;
struct sob{int a; int b;} s[100005];

bool my_sort(struct sob x, struct sob y)
{	if(x.a > y.a && x.b < y.b)
		return true;
	return false;
}

void my_print()
{	int i;
	for(i=0; i<n; ++i)
		printf("%d\t%d\n", s[i].a, s[i].b);
}

int main()
{	int i, j;

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	for(i=0; i<n; ++i)
		scanf("%d %d", &s[i].a, &s[i].b);
	sort(s, s+n, my_sort);

	//my_print();

	for(i=0; i<n; ++i)
	{	for(j=i+1; j<n; j++)
			if(s[j].a < s[i].a && s[j].b > s[i].b)
			{	cnt++;
				break;
			}
	}

	printf("%d", cnt);
	return 0;
}


//WA15
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

int n, cnt;
struct sob{int a; int b;} s[100005];
vector<int> bb;
vector<int>::iterator it;

bool my_sort(struct sob x, struct sob y)
{	if(x.a < y.a)
		return true;
	return false;
}

void my_print()
{	int i;
	for(i=0; i<n; ++i)
		printf("%d\t%d\n", s[i].a, s[i].b);
}

int main()
{	int i;

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	for(i=0; i<n; ++i)
		scanf("%d %d", &s[i].a, &s[i].b);
	sort(s, s+n, my_sort);

	//my_print();

	for(i=0; i<n; ++i)
	{
		it = upper_bound(bb.begin(), bb.end(), s[i].b);
		if(it == bb.end())
			bb.push_back(s[i].b);
		else
		{
			cnt++;
			bb.insert(it, s[i].b);
		}
	}

	printf("%d", cnt);
	return 0;
}


#include <stdio.h>
#include <algorithm>
using namespace std;

int n, cnt;
struct sob{int a; int b;} s[100005];

bool my_sort(struct sob x, struct sob y)
{	if(x.a < y.a)
		return true;
	return false;
}

void my_print()
{	int i;
	for(i=0; i<n; ++i)
		printf("%d\t%d\n", s[i].a, s[i].b);
}

int main()
{	int i, j;

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	for(i=0; i<n; ++i)
		scanf("%d %d", &s[i].a, &s[i].b);
	sort(s, s+n, my_sort);

	//my_print();

	for(i=1; i<n; ++i)
	{	for(j=i-1; j>=0; j--)
			if(s[j].b > s[i].b)
			{	cnt++;
				break;
			}
	}

	printf("%d", cnt);
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define size 100001
typedef struct node
{
    long begin;
    long end;
}node;
node h[size];
long statis[size];
long n;
int cmp_begin(const void* x,const void* y)
{
    node a,b;
    a=*(node*)x;b=*(node*)y;
    if(a.begin>b.begin)return 1;
    else    return -1;
}
int cmp_end(const void* x,const void* y)
{
    node a,b;
    a=*(node*)x;b=*(node*)y;
    if(a.end > b.end)return 1;
    else    return -1;
}
int main()
{
    long i,max;
    scanf("%ld",&n);
    for(i=0;i<n;i++)
    scanf("%ld%ld",&h[i].begin,&h[i].end);
    qsort(h,n,sizeof(node),cmp_begin);
    for(i=0;i<n;i++)
    h[i].begin=i;
    qsort(h,n,sizeof(node),cmp_end);
    for(i=0;i<n;i++)
    h[i].end=i;
    qsort(h,n,sizeof(node),cmp_begin);
    for(i=0;i<n;i++)
        statis[i]=n-1-h[i].end;
    for(i=0,max=0;i<n;i++)
    if(statis[i]>max)max=statis[i];
    printf("%ld\n",max);
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define size 100001
typedef struct node
{
    long begin;
    long end;
}node;
node h[size];
long statis[size];
long n;
int cmp_begin(const void* x,const void* y)
{
    node a,b;
    a=*(node*)x;b=*(node*)y;
    if(a.begin>b.begin)return 1;
    else    return -1;
}
int cmp_end(const void* x,const void* y)
{
    node a,b;
    a=*(node*)x;b=*(node*)y;
    if(a.end > b.end)return 1;
    else    return -1;
}
int main()
{
    long i,max,max_end,flag;
    scanf("%ld",&n);
    for(i=0;i<n;i++)
    scanf("%ld%ld",&h[i].begin,&h[i].end);
    qsort(h,n,sizeof(node),cmp_begin);
    for(i=0;i<n;i++)
    h[i].begin=i;
    qsort(h,n,sizeof(node),cmp_end);
    for(i=0;i<n;i++)
    h[i].end=i;
    qsort(h,n,sizeof(node),cmp_begin);
    for(i=0,max_end=0,flag=0;i<n;i++)
    {
        if(max_end>h[i].end)continue;
        max_end=h[i].end;
        statis[i]=h[i].end-flag;
        flag++;
    }
    for(i=0,max=0;i<n;i++)
    if(statis[i]>max)max=statis[i];
    printf("%ld\n",max);
    return 0;
}


n = int(input())
a = []
d = {}
for i in range(n):
    l, r = [int(x) for x in input().split()]
    a.append([l, r])
    d[l] = r
a.sort()
b = []
t = -1
res = 0
for i in range(len(a)):
    if a[i][1] < t:
        res += 1
    t = max(d[a[i][0]], t)
#print(a)
print(res)


n = int(input())
a = []
for i in range(n):
    l, r = [int(x) for x in input().split()]
    a.append([l, 0])
    a.append([r, 1])
a.sort()
cur = 0
res = 0
for i in range(len(a)):
    if a[i][1] == 0:
        cur += 1
    else:
        if cur > 1:
            res += 1
        cur -= 1
print(res)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
# from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
# import numpy as np
starttime = time.time()
# import numpy as np
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

try:
    # sys.setrecursionlimit(int(pow(10,5)))
    sys.stdin = open("input.txt", "r")
    # sys.stdout = open("../output.txt", "w")
except:
    pass

n=L()[0]
A=[L() for i  in range(n)]
A.sort()
stk=[A[0]]
for i in range(1,n):
    s,e=A[i]
    if stk[-1][0]<s and e<stk[-1][1]:
        continue
    else:
        stk.append([s,e])
print(n-len(stk))

endtime = time.time()
# print(f"Runtime of the program is {endtime - starttime}")


n=int(input())
arr=[]
for i in range(n):
	x=list(map(int,input().split()))
	arr.append((x[0],x[1]))
arr.sort()
ans=0
m=arr[0][1]
for i in range(1,n):
	if arr[i][1]<m:
		ans+=1
	m=max(arr[i][1],m)
print(ans)


n=int(input())
arr=[]
for i in range(n):
	x=list(map(int,input().split()))
	arr.append((x[0],x[1]))
arr.sort()
ans=0
m=arr[0][1]
for i in range(1,n):
	if arr[i][1]<m:
		ans+=1
	m=min(arr[i][1],m)
print(ans)


n=int(input())
l=[]
for i in range(n):
    a,b=map(int,input().split())
    l.append((a,b))
l.sort()
a=l[0][0]
b=l[0][1]
c=0
for i in range(1,n):
    if l[i][0]>a and l[i][1]<b:
        c+=1
    else:
        a=l[i][0]
        b=l[i][1]
print(c)


n=int(input())
l=[]
for i in range(n):
    a,b=map(int,input().split())
    l.append((a,b))
l.sort()
a=l[0][0]
b=l[0][1]
c=0
for i in range(1,n):
    if l[i][0]>a and l[i][1]<b:
        c+=1
    else:
        a=l[i][0]
        b=[i][1]
print(c)


size = int(input());history = [];overlap = 0
for _ in range(size):
    a,b = map(int,input().split())
    history.append((a,b))
history.sort();begin = history[0][1];h,j = 1,1
while h < size:
    while j < size:
        if begin > history[j][1]:
            overlap+=1
        else:
            h = j; begin = history[j][1]
            break
        j+=1
    h = j
print (overlap)


size = int(input());history = [];overlap = 0
for _ in range(size):
    a,b = map(int,input().split())
    history.append((a,b))
history.sort();begin = history[0][1];h,j = 1,1
while h < size:
    while j < size:
        if begin > history[j][1]:
            overlap+=1
        else:
            begin = history[j][1]
            j+=1
            break
        j+=1
    h = j
print (overlap)


size = int(input());history = [];overlap = 0
for _ in range(size):
    a,b = map(int,input().split())
    history.append((a,b))
history.sort();begin = history[0][1];h,j = 1,1
while h < size:
    while j < size:
        if begin > history[j][1]:
            overlap+=1
        else:
            h = j; begin = history[j][1]
            j+=1
            break
        j+=1
    h = j
print (overlap)


N = int(input())
events = []
for i in range(N):
  ai, bi = list(map(int, input().split()))
  events.append((ai, bi))

events.sort()

r = -1
c = 0
for event in events:
  if event[1] <= r:
    c += 1
  else:
    r = max(r, event[1])

print(c)


n=int(input())
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
ans=0
l.sort()
i=0
while i<n:
    t=l[i][1]
    while l[i][1]<=t:
        ans=ans+1
        i=i+1
        if i==n:
            break
    ans=ans-1
print(ans)


n= int(input())
p = [tuple(map(int, input().split())) for x in range(n)]
p.sort(key = lambda x: x[0])

ans = 0
max_e = 0
for i in range(n):
	if p[i][1] < max_e:
		ans += 1
	else:
		max_e = max(max_e, p[i][1])

print(ans)


n = int(input())
spans = [ tuple(map(int, input().split())) for i in range(n) ]
spans.sort()
result = 0
rightmost = spans[0][1]
for span in spans[1:]:
    if span[1] < rightmost:
        result += 1
    else:
        rightmost = span[1]
print(result)


class Span:
    def __init__(self, open, close):
        self.open = open
        self.close = close
        self.closed = False

    def __str__(self):
        return '[%d, %d]' % (self.open, self.close)

class Event:
    def __init__(self, point, span, opening=False, closing=False):
        self.point = point
        self.span = span
        self.opening = opening
        self.closing = closing

    def __str__(self):
        return '(%d %s)' % (self.point, 'open' if self.opening else 'close')

n = int(input())
spans = n * [ None ]
events = 2 * n * [ None ]
for i in range(n):
    open, close = map(int, input().split())
    spans[i] = Span(open, close)
    events[2 * i] = Event(open, spans[i], opening=True)
    events[2 * i + 1] = Event(close, spans[i], closing=True)
events.sort(key=lambda event: event.point)
result = 0

queue = []
leftmost = 0
for event in events:
    span = event.span
    if event.opening:
        span.queue_pos = len(queue)
        queue.append(span)
    else:
        if queue[leftmost].open < span.open:
            result += 1
        queue[span.queue_pos].closed = True
        while leftmost < len(queue) and queue[leftmost].closed:
            leftmost += 1

print(result)


a = []
for _ in range(int(input())): a.append(list(map(int, input().split())))
m, s = -1, 0
for i, j in sorted(a):
    if j > m:
        m = j
    else:
        s+=1
print(s)


n=int(input())
li=[]
for i in range(n):
    x,y=map(int,input().split(" "))
    li.append([x,y])
li.sort()
ans,r=0,li[0][1]
for i in range(1,n):
    if li[i][1]<=r:
        ans+=1
    else:
        r=li[i][1]
print(ans)


n = int(input())
s = []
for _ in range(n):
    a,b = map(int,input().split())
    s.append([a,b])
s.sort(key = lambda x: x[0])
ans = 0
mx = s[0][1]
for i in range(1,n):
    if(s[i][1]<mx):
        ans+=1
    elif(s[i][1]>mx):
        mx = s[i][1]
print(ans)


// A C++ program for merging overlapping intervals
#include<bits/stdc++.h>
using namespace std;

// An interval has start time and end time
struct Interval
{
	int start, end;
};

// Compares two intervals according to their staring time.
// This is needed for sorting the intervals using library
// function std::sort(). See http://goo.gl/iGspV
bool compareInterval(Interval i1, Interval i2)
{
	return (i1.start < i2.start);
}

// The main function that takes a set of intervals, merges
// overlapping intervals and prints the result
int mergeIntervals(Interval arr[], int n)
{

	// Create an empty stack of intervals
	stack<Interval> s;

	// sort the intervals in increasing order of start time
	sort(arr, arr+n, compareInterval);

	// push the first interval to stack
	s.push(arr[0]);

	// Start from the next interval and merge if necessary
	for (int i = 1 ; i < n; i++)
	{
		// get interval from stack top
		Interval top = s.top();

		// if current interval is not overlapping with stack top,
		// push it to the stack
		if (top.end < arr[i].start)
			s.push(arr[i]);

		// Otherwise update the ending time of top if ending of current
		// interval is more
		else if (top.end < arr[i].end)
		{
			top.end = arr[i].end;
			s.pop();
			s.push(top);
		}
	}

	return n  - s.size();
}

// Driver program
int main()
{
	int n; cin>>n;
	Interval arr[n];
	for(int i=0; i<n; ++i)
    {
        int a,b; cin>>a>>b;
        arr[i].start = a;
        arr[i].end = b;
    }
	cout<<mergeIntervals(arr, n);
}


n = int(input())
s = []
for _ in range(n):
    a,b = map(int,input().split())
    s.append([a,b])
s.sort(key = lambda x: (x[0],-1*x[1]))
ans = 0
#print(s)
for i in range(1,n):
    cur = s[i]
    if(cur[0]>s[0][0] and cur[1]<s[0][1]):
        ans+=1
print(ans)


# import sys
# sys.stdin = open("F:\\Scripts\\input","r")
# sys.stdout = open("F:\\Scripts\\output","w")

MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))

n, = I()
l = []
for i in range(n):
	l.append(I())
x = sorted(l)
m = x[0][0]
count = 0
for i in x:
	if i[1] < m :
		count += 1
	if i[1] > m:
		m = i[1]
print(count)


n = int(input())
event = []
for i in range(n):
    a, b = [int(x) for x in input().split()]
    l = [a, b]
    event.append(l)
event.sort()

num = 0
en = event[0][1]
for i in range(1, n):
    s = event[i][1]
    if s < en:
        num += 1
    en = max(en, s)
print(num)


n = int(input())
event = []
for i in range(n):
    a, b = [int(x) for x in input().split()]
    l = [b, a]
    event.append(l)
event.sort()
start = []
end = []
for i in range(n):
    a = event[i][1]
    b = event[i][0]
    start.append(a)
    end.append(b)
num = 0
for i in range(n):
    s = start[i]
    a = 0
    for j in range(i + 1, n):
        if start[j] < s:
            a = 1
    if a == 1:
        num += 1
print(num)


n = int(input())
event = []
for i in range(n):
    a, b = [int(x) for x in input().split()]
    l = [a, b]
    event.append(l)
event.sort()
start = []
end = []
for i in range(n):
    a = event[i][0]
    b = event[i][1]
    start.append(a)
    end.append(b)
num = 0
for i in range(n):
    s = end[i]
    a = 0
    for j in range(0, i):
        if end[j] > s:
            a = 1
            break
    if a == 1:
        num += 1
print(num)


t = [tuple(map(int, input().split())) for i in range(int(input()))]
t.sort()
c, s = 0, 0
for a, b in t:
    if b < c: s += 1
    if b > c: c = b
print(s)


n = int(input())
A=[]
B=[]
tot=0
for _ in range(n):
    L=[int(i) for i in input().split()]
    A.append(L[0])
    B.append(L[1])
for i in range(n):
    for j in range(n):
        if (A[i]<A[j]) & (B[j]<B[i]):
            tot+=1
            break
print (tot)


n = int(input())
A=[]
B=[]
tot=0
for i in range(n):
    A.append(int(input().split()[0]))
    B.append(int(input().split()[1]))
for i in range(n):
    for j in range(n):
        if (A[i]<A[j]) & (B[j]<B[i]):
            tot+=1
            break
print (tot)


n = int(input())
A=[]
B=[]
tot=0
for _ in range(n):
    L=[int(i) for i in input().split()]
    A.append(L[0])
    B.append(L[1
for i in range(n):
    for j in range(n):
        if (A[i]<A[j]) & (B[j]<B[i]):
            tot+=1
            break
print (tot)


n = int(input())
A=[]
B=[]
tot=0
for _ in range(n):
    L=[int(i) for i in input().split()]
    A.append(L[0]))
    B.append(L[1]))
for i in range(n):
    for j in range(n):
        if (A[i]<A[j]) & (B[j]<B[i]):
            tot+=1
            break
print (tot)


n = int(input())
A=[]
B=[]
tot=0
for _ in range(n):
    L=[int(i) for i in input().split()]
    A.append(L[0])
    B.append(L[1])
for j in range(n):
    for i in range(n):
        if (A[i]<A[j]) & (B[j]<B[i]):
            tot+=1
            break
print (tot)


c, s = 0, 0
for a, b in [tuple(map(int, input().split())) for i in range(int(input()))].sort():
    if b < c: s += 1
    if b > c: c = b
print(s)


n = int(input())
arr=[]
for _ in range(n):
    x,y = map(int,input().split())
    arr.append((x,y))
c=0
arr.sort(key=lambda arr:arr[0])

rg = arr[0][1]

for i in range(n):
    if arr[i][1]<rg:
        c+=1
    else:
        rg=arr[i][1]
print (c)


n = int(input())
arr=[]
for _ in range(n):
    x,y = map(int,input().split())
    arr.append((x,y))
c=0
arr.sort(key=lambda arr:arr[0])

visited = []
for i in range(n):
    low = arr[i][0]
    high = arr[i][1]
    for j in range(i+1,n):
        if j not in visited:
            if arr[j][1]<=high and arr[j][0]>=low:
                c+=1
                visited.append(j)

print (c)


n = int(input())
I = lambda :map(int,input().split())
li = []
for _ in range (n) :
    x, y = I()
    li.append((x,y))
li.sort()
#print(li)
x , y = li[0]
minn = x
maxx = y
ans =  0
for _ in range (1,n) :
    x , y = li[_]
    #print(x,y)
    if maxx > y :
        ans+=1
    maxx = max(maxx,y)
print(ans)


import sys
input=sys.stdin.buffer.readline
I=lambda:list(map(int,input().split()))
n,=I()
ar=[]
for i in range(n):
	ar.append(I())
ar.sort()
cur=ar[0][1]
ans=0
for i in range(1,n):
	if ar[i][1]<cur:
		ans+=1
	else:
		cur=ar[i][1]
print(ans)


import sys
import math

n=int(input())
k=[]
for i in range(n):
    a,b=map(int,input().split())
    k.append((a,b))
k.sort()
t,con=0,0
for (a,b) in k:
    if(b<t):
        con+=1
    else:
        t=b
print(con)


n = int(input())
t = [tuple(map(int, input().split())) for i in range(n)]
k, j = 2 * n, 0
p = [0] * k
for i, (a, b) in enumerate(t):
    p[j] = (a, 0, i)
    j += 1
    p[j] = (b, 1, i)
    j += 1
p.sort()
s, r = 0, []
for i in p:
    if i[1]:
        if r[0] != i[2]: s += 1
        r.remove(i[2])
    else: r.append(i[2])
print(s)


t = [tuple(map(int, input().split())) for i in range(int(input()))]
c, s = 0, 0
for a, b in t:
    if b < c: s += 1
    if b > c: c = b
print(s)


t = [tuple(map(int, input().split())) for i in range(int(input()))]

t.sort()

c, s = 0, 0

for a, b in t:

    if b < c: s += 1

    if b > c: c = b

print(s)

# Made By Mostafa_Khaled


t = [tuple(map(int, input().split())) for i in range(int(input()))]
t.sort()

c, s = 0, 0

for a, b in t:

	if b < c:
		s += 1
	if b > c:
		c = b

print(s)


n = int(input())
event = []
for i in range(n):
    a, b = map(int,input().split())
    event.append([a,b])
event.sort()
ly = event[0][1]
ans = 0
for i in event:
    ly = max(ly,i[1])
    if ly > i[1]:
        ans += 1
print(ans)


n=int(input())
arr=[]
for _ in range(n):
    a,b=[int(x) for x in input().split()]
    arr.append([a,'S',_])
    arr.append([b,'E',_])
arr.sort()
stack=set()
l=0
ans=0
mini=100000000000000
for i in arr:
    #print(stack)
    if i[1]=='S':
        stack.add(i[2])
        mini=min(mini,i[2])
    elif i[1]=='E':
        if i[2] in stack and i[2]!=mini:
            ans+=1
            #print(i)
            stack.remove(i[2])
        elif i[2] in stack:
            stack.remove(i[2])
            if stack:
                mini=min(stack)
            else:
                mini=100000000000000

print(ans)


n=int(input())
arr=[]
for _ in range(n):
    a,b=[int(x) for x in input().split()]
    arr.append([a,b])
arr.sort()
maxi=arr[0][1]
ans=0
for i in range(1,n):
    maxi=max(maxi,arr[i][1])
    if maxi>arr[i][1]:
        ans+=1
print(ans)


n=int(input())
arr=[]
for _ in range(n):
    a,b=[int(x) for x in input().split()]
    arr.append([a,'S',_])
    arr.append([b,'E',_])
arr.sort()
stack=set()
l=0
ans=0
mini=100000000000000
for i in arr:
    if i[1]=='S':
        stack.add(i[2])
        mini=min(mini,i[2])
    elif i[1]=='E':
        if i[2] in stack and i[2]!=mini:
            ans+=1
            stack.remove(i[2])
        else:
            stack.remove(i[2])
            if stack:
                mini=min(stack)

print(ans)


# Getting Problem-Data from Codeforces.
eventCount,pairs = int(input()),[]
for i in range(eventCount):
    newPair = tuple(map(int,input().split(' ')))
    pairs.append(newPair)
# Sorting Pairs by first componenet.
from operator import itemgetter
pairs.sort(key=itemgetter(0))
# Method to detemine if event-a contains event-b.
def isIncluded(a,b):
    return a[0]<b[0] and b[1]<a[1]
# Algorithm.
prev,count = pairs[0],0
for j in range(1,eventCount):
    if isIncluded(prev,pairs[j]):
        count = count+1
    prev = pairs[j]
print(count)


# Getting Problem-Data from Codeforces.
eventCount,pairs = int(input()),[]
for i in range(eventCount):
    newPair = tuple(map(int,input().split(' ')))
    pairs.append(newPair)
# Sorting Pairs by first componenet.
from operator import itemgetter
pairs.sort(key=itemgetter(0))
# Method to detemine if event-a contains event-b.
def isIncluded(a,b):
    return a[0]<b[0] and b[1]<a[1]
# Method to deduce which of the two events is larger.
def maxEvent(a,b):
    if b[1]>a[1]:return b
    else: return a
# Algorithm.
maxPrev,count = pairs[0],0
for j in range(1,eventCount):
    if isIncluded(maxPrev,pairs[j]):
        count = count+1
    maxPrev = maxEvent(maxPrev,pairs[j])
# Solution.
print(count)


# Getting Problem-Data from Codeforces.
eventCount,pairs = int(input()),[]
for i in range(eventCount):
    newPair = tuple(map(int,input().split(' ')))
    pairs.append(newPair)
# Sorting Pairs by first componenet.
from operator import itemgetter
pairs.sort(key=itemgetter(0))
# Method to detemine if event-a contains event-b.
def isIncluded(a,b):
    return a[0]<b[0] and b[1]<a[1]
# Method to deduce which of the two events is larger.
def maxEvent(a,b):
    if a[1]-a[0] > b[1]-b[0]:
        return a
    else: return b
# Algorithm.
maxPrev,count = pairs[0],0
for j in range(1,eventCount):
    if isIncluded(maxPrev,pairs[j]):
        count = count+1
    maxPrev = maxEvent(maxPrev,pairs[j])
# Solution.
print(count)


# Getting Problem-Data from Codeforces.
eventCount,pairs = int(input()),[]
for i in range(eventCount):
    newPair = tuple(map(int,input().split(' ')))
    pairs.append(newPair)
# Sorting Pairs by first componenet.
from operator import itemgetter
pairs.sort(key=itemgetter(0))
# Method to detemine if event-a contains event-b.
def isIncluded(a,b):
    return a[0]<b[0] and b[1]<a[1]
# Method to deduce which of the two events is larger.
def maxEvent(a,b):
    if b[1]-b[0] > a[1]-a[0]:
        return b
    else: return a
# Algorithm.
maxPrev,count = pairs[0],0
for j in range(1,eventCount):
    if isIncluded(maxPrev,pairs[j]):
        count = count+1
    maxPrev = maxEvent(maxPrev,pairs[j])
# Solution.
print(count)


# Getting Problem-Data from Codeforces.
eventCount,pairs = int(input()),[]
for i in range(eventCount):
    newPair = tuple(map(int,input().split(' ')))
    pairs.append(newPair)
# Sorting Pairs by first componenet.
from operator import itemgetter
pairs.sort(key=itemgetter(0))
# Method to detemine if event-a contains event-b.
def isIncluded(a,b):
    return a[0]<b[0] and b[1]<a[1]
# Algorithm.
prev,count = pairs[0],0
for j in range(1,eventCount):
    if isIncluded(prev,pairs[j]):
        count = count+1
print(count)


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main(){
    string s;
    cin>>s;
    int q;
    scanf("%d",&q);
    int arr[s.size()+1];
    arr[0] = 0;
    for(int i=1;i<s.size();i++){
        if(s[i]==s[i-1]){
            arr[i]=arr[i-1]+1;
        }else{
            arr[i]=arr[i-1];
        }
    }
    int l,r;
    while(q--){
        scanf("%d %d",&l,&r);
        printf("%d\n",arr[r-1]-arr[l-1]);
    }
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

    string s;
    cin>>s;
    int q;
    scanf("%d",&q);
    int arr[s.size()+1];
    arr[0] = 0;
    for(int i=1;i<s.size();i++){
        if(s[i]==s[i-1]){
            arr[i]=arr[i-1]+1;
        }else{
            arr[i]=arr[i-1];
        }
    }
    int l,r;
    while(q--){
        cin >> l >> r;
        cout << arr[r-1]-arr[l-1] << endl;
    }
}


#include <iostream>
#include <string>
using namespace std;

#define DEBUG 1

int main(){
	string str;
	int numOfQuery;
	int* query[2];
	getline(cin,str);
	cin >> numOfQuery;
	query[0] = (int*) malloc(numOfQuery * sizeof(int));
	query[1] = (int*) malloc(numOfQuery * sizeof(int));
	for(int i=0 ; i<numOfQuery ; i++)
		cin >> query[0][i] >> query[1][i];
	#if DEBUG
		cout << numOfQuery << query[0][0] << query[0][1];
	#endif

}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main(){
    string s;
    cin>>s;
    int q;
    scanf("%d",&q);
    int arr[s.size()+1];
    arr[0] = 0;
    for(int i=1;i<s.size();i++){
        if(s[i]==s[i-1]){
            arr[i]=arr[i-1]+1;
        }else{
            arr[i]=arr[i-1];
        }
    }
    int l,r;
    while(q--){
        cin >> l >> r;
        cout << arr[r-1]-arr[l-1] << endl;
    }
}


#include <iostream>
#include <string>
using namespace std;

#define DEBUG 1

int main(){
	string str;
	int numOfQuery;
	getline(cin,str);
	cin >> numOfQuery;
	for(int i=0 ; i<numOfQuery ; i++) {
		int query[2];
		cin >> query[0] >> query[1];
		int count = 0;
		int p = -1;
		if(str[query[0]-1] == '.')
			p = query[0]-1;
		for(int j=query[0] ; j<query[1] ; j++) {
			if(str[j] == '.') {
				if(p == j-1)
					count += 1;
				p = j;
			} else {
				if(p != j-1)
					count += 1;
			}
		}
		cout << count;
	}

}


#include <iostream>
#include <string>
using namespace std;

#define DEBUG 1

int main(){
	string str;
	int numOfQuery;
	getline(cin,str);
	cin >> numOfQuery;
	int resultArr[str.length()] = {0};
	int p = -1;
	if(str[0] == '.')
		p = 0;
	for(int i=1 ; i<str.length() ; i++) {
		if(str[i] == '.') {
			if(p == i-1)
				resultArr[i] = resultArr[i-1] + 1;
			else
				resultArr[i] = resultArr[i-1];
			p = i;
		} else {
			if(p != i-1)
				resultArr[i] = resultArr[i-1] + 1;
			else
				resultArr[i] = resultArr[i-1];
		}
	}
	for(int i=0 ; i<numOfQuery ; i++) {
		int query[2];
		cin >> query[0] >> query[1];
		cout << resultArr[query[1]-1] - resultArr[query[0]-1] << endl;
	}
}


#include <iostream>
#include <string>
using namespace std;

int main(){
	string str;
	int numOfQuery;
	int* query[2];
	getline(cin,str);
	cin >> numOfQuery;
	query[0] = (int*) malloc(numOfQuery * sizeof(int));
	query[1] = (int*) malloc(numOfQuery * sizeof(int));
	for(int i=0 ; i<numOfQuery ; i++)
		cin >> query[i][0] >> query[i][1];
	cout << numOfQuery << query[0][0] << query[0][1];
}


#include <iostream>
#include <string>
using namespace std;

#define DEBUG 1

int main(){
	string str;
	int numOfQuery;
	getline(cin,str);
	cin >> numOfQuery;
	for(int i=0 ; i<numOfQuery ; i++) {
		int query[2];
		cin >> query[0] >> query[1];
		int count = 0;
		int p = -1;
		if(str[query[0]-1] == '.')
			p = query[0]-1;
		for(int j=query[0] ; j<query[1] ; j++) {
			if(str[j] == '.') {
				if(p == j-1)
					count += 1;
				p = j;
			} else {
				if(p != j-1)
					count += 1;
			}
		}
		cout << count << endl;
	}

}


#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    long long n = s.length();
    long long arr[n];
    int k = 0;
    for(int i = 0;i < n;i++)  {
        if(s[i] == s[i + 1]) {
           k++;
           arr[i] = k;
        }
        else arr[i] = 0;
    }
    for(int i = 1;i < n;i++) arr[i] += arr[i - 1];
    int m;
    cin>>m;
    for(int i = 0;i < m;i++){
        int li,ri;
        cin>>li>>ri;
        cout<<arr[ri-1] - arr[li-1]<<endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    long long n = s.length();
    long long arr[n];
    int k = 0;
    for(int i = 0;i < n;i++)  {
        if(s[i] == s[i + 1]) {
           arr[i] = 1;
        }
        else arr[i] = 0;
    }
    for(int i = 1;i < n;i++) arr[i] += arr[i - 1];
    int m;
    cin>>m;
    for(int i = 0;i < m;i++){
        int li,ri;
        cin>>li>>ri;
        cout<<arr[ri-1] - arr[li-1]<<endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    int n = s.length();
    int arr[n];
    for(int i = 0;i < n;i++)  {
        if(s[i] == s[i + 1]) arr[i] = 1;
        else arr[i] = 0;
    }
    for(int i = 1;i < n;i++) arr[i] += arr[i - 1];
    int m;
    cin>>m;
    for(int i = 0;i < m;i++){
        int li,ri;
        cin>>li>>ri;
        li--,ri--;
        cout<<arr[ri] - arr[li]<<endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    long long n = s.length();
    long long arr[n];
    int k = 0;
    for(int i = 0;i < n - 1;i++)  {
        if(s[i] == s[i + 1]) {
           arr[i] = 1;
        }
        else arr[i] = 0;
    }
    for(int i = 1;i < n;i++) arr[i] += arr[i - 1];
    int m;
    cin>>m;
    for(int i = 0;i < m;i++){
        int li,ri;
        cin>>li>>ri;
        cout<<arr[ri-1] - arr[li-1]<<endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    int n = s.length();
    int arr[n];
    for(int i = 0;i < n;i++)  {
        if(s[i] == s[i + 1]) arr[i + 1] = 1;
        else arr[i + 1] = 0;
    }
    for(int i = 1;i < n;i++) arr[i] += arr[i - 1];
    int m;
    cin>>m;
    for(int i = 0;i < m;i++){
        int li,ri;
        cin>>li>>ri;
        cout<<arr[ri-1] - arr[li-1]<<endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    int n = s.length();
    int arr[n];
    for(int i = 0;i < n;i++)  {
        if(s[i] == s[i + 1]) arr[i] = 1;
        else arr[i] = 0;
    }
    for(int i = 1;i < n;i++) arr[i] += arr[i - 1];
    int m;
    cin>>m;
    for(int i = 0;i < m;i++){
        int li,ri;
        cin>>li>>ri;
        cout<<arr[ri-1] - arr[li-1]<<endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    int n = s.length();
    int arr[n];
    int k = 0;
    for(int i = 0;i < n - 1;i++)  {
        if(s[i] == s[i + 1]) {
           k++;
           arr[i] = k;
        }
        else arr[i] = 0;
    }
    for(int i = 1;i < n;i++) arr[i] += arr[i - 1];
    int m;
    cin>>m;
    for(int i = 0;i < m;i++){
        int li,ri;
        cin>>li>>ri;
        cout<<arr[ri-1] - arr[li-1]<<endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    int n = s.length();
    int arr[n];
    for(int i = 0;i < n - 1;i++)  {
        if(s[i] == s[i + 1]) arr[i] = 1;
        else arr[i] = 0;
    }
    for(int i = 1;i < n;i++) arr[i] += arr[i - 1];
    int m;
    cin>>m;
    for(int i = 0;i < m;i++){
        int li,ri;
        cin>>li>>ri;
        cout<<arr[ri-1] - arr[li-1]<<endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    int n = s.length();
    int arr[n];
    for(int i = 0;i < n;i++)  {
        if(s[i] == s[i + 1]) arr[i] = 1;
        else arr[i] = 0;
    }
    for(int i = 1;i < n;i++) arr[i] += arr[i - 1];
    int m;
    cin>>m;
    for(int i = 0;i < m;i++){
        int li,ri;
        cin>>li>>ri;
        l--,r--;
        cout<<arr[ri] - arr[li]<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main() {
    string s;
    cin >> s;
    int m;
    cin >> m;
    while(m--) {
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        int count = 0;
        char temp = s[l];
        for(int i = l; i < r; i++)
            if(temp == s[i])
                count++;
        cout << count << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

int main() {
    string s;
    cin >> s;
    int m;
    cin >> m;
    while(m--) {
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        int count = 0;
        char temp = s[l];
        for(int i = l+1; i < r; i++)
            if(temp == s[i])
                count++;
        cout << count << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

int main() {
    string s;
    cin >> s;
    int m;
    cin >> m;
    int a[s.length()] = {0};
    if(s[0] == s[1])
        a[0] = 1;
    for(int i = 1; i < s.length() - 1; i++) {
        if(s[i] == s[i+1])
            a[i] = a[i-1] + 1;
        else
            a[i] = a[i-1];
    }
    a[s.length()-1] = a[s.length()-2] + 1;
    while(m--) {
        int l, r;
        cin >> l >> r;
        cout << a[r-1] - a[l-1] << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

int main() {
    string s;
    cin >> s;
    int m;
    cin >> m;
    while(m--) {
        int l, r;
        cin >> l >> r;
        int count = 0;
        char temp = s[l];
        for(int i = l+1; i < r; i++)
            if(temp == s[i])
                count++;
        cout << count << endl;
    }
}


#include <cstdio>
#include <cstring>

int main()
{
    char s[100001];
    int a[100001], m, l, r;

    scanf("%s%d", s, &m);
    int len = strlen(s);

    a[1] = 0;
    for (int i = 1; i < len; ++i)
    {
        if (s[i] == s[i-1])
        {
            a[i+1] = a[i] + 1;
        }
        else
        {
            a[i+1] = a[i];
        }
    }

    while (m--)
    {
        scanf("%d%d", &l, &r);
        printf("%d\n", a[r] - a[l]);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main() {
    string s;
    cin >> s;
    int m;
    cin >> m;
    int a[s.length()];
    if(s[0] == s[1])
        a[0] = 1;
    for(int i = 1; i < s.length() - 1; i++) {
        if(s[i] == s[i+1])
            a[i] = a[i-1] + 1;
    }
    while(m--) {
        int l, r;
        cin >> l >> r;
        cout << a[r-1] << endl;
    }
}