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

typedef long long int ll;

//<---------------------------------------------useful functions------------------------------------------------>

bool is_square(ll x){ll y=sqrt(x);   return (x==(y*y));}
ll lcm(ll x,ll y){return  ((x/__gcd(x,y))*y);}
ll h_pow_2_less_x(ll x){
    if(x==0)        return 0;
    ll y=1;
    while((y*2)<=x)     y=y<<1;
    return y;
}
ll ceil_div(ll x,ll y){return ((x/y)+((x%y)!=0));}      //returns ceil(x/y);

//<---------------------------------------------useful functions------------------------------------------------>

void run_case(){
    int i,n,ans=0,j;
    cin>>n;
    vector<int>v(n);
    set<pair<int,int>>pos;
    pair<int,int>p;
    for(i=0;i<n;i++)        cin>>v[i],pos.insert({-v[i],i});
    for(i=n-1;i>0;i--){
        p=*pos.begin();
        if(p.first==(-v[i])){
            p.second=i;
            pos.erase(p);
        }
        else{
            j=p.second;
            pos.erase(p);
            p.first=(-v[i]);p.second=i;
            pos.erase(p);
            swap(v[j],v[i]);
            ans++;
            pos.insert({-v[j],j});
        }
    }
    cout<<ans;
    cout<<"\n";
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t=1;
    while(t--)      run_case();
    return 0;
}