#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <ll,ll> p;
const int N = 1e5+34;

ll a[N],b[N],n;
ll novi[N],dp[N];
p nesto[N];

ll Resi(int N,int *A,int *B){
    n = N;
    for(int i = 1; i <= n; i++){
        a[i] = A[i-1];
        b[i] = B[i-1];
        nesto[i] = p(a[i],b[i]);
    }
    sort(nesto+1,nesto+n+1);
    for(int i = 1; i <= n; i++){
        novi[i] = b[i];
    }
    dp[0] = 1;
    for(int i = 1; i <= n; i++){
        dp[i] = 1;
        for(int j = i-1; j >= 1; j--){
            if(novi[j] < novi[i]){
                dp[i] = max(dp[i],dp[j]+1);
            }
        }
    }
    return n-dp[n];
}
/*int main(){
    int n1[4],n2[4];
    n1[0] = 0;
    n1[1] = 1;
    n1[2] = 2;
    n1[3] = 5;
    n2[0] = 3;
    n2[1] = 7;
    n2[2] = 4;
    n2[3] = 6;
    cout << Resi(4,n1,n2) << endl;
}*/