#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;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnR5cGVkZWYgbG9uZyBsb25nIGludCBsbDsKCi8vPC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLXVzZWZ1bCBmdW5jdGlvbnMtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0+Cgpib29sIGlzX3NxdWFyZShsbCB4KXtsbCB5PXNxcnQoeCk7ICAgcmV0dXJuICh4PT0oeSp5KSk7fQpsbCBsY20obGwgeCxsbCB5KXtyZXR1cm4gICgoeC9fX2djZCh4LHkpKSp5KTt9CmxsIGhfcG93XzJfbGVzc194KGxsIHgpewogICAgaWYoeD09MCkgICAgICAgIHJldHVybiAwOwogICAgbGwgeT0xOwogICAgd2hpbGUoKHkqMik8PXgpICAgICB5PXk8PDE7CiAgICByZXR1cm4geTsKfQpsbCBjZWlsX2RpdihsbCB4LGxsIHkpe3JldHVybiAoKHgveSkrKCh4JXkpIT0wKSk7fSAgICAgIC8vcmV0dXJucyBjZWlsKHgveSk7CgovLzwtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS11c2VmdWwgZnVuY3Rpb25zLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tPgoKdm9pZCBydW5fY2FzZSgpewogICAgaW50IGksbixhbnM9MCxqOwogICAgY2luPj5uOwogICAgdmVjdG9yPGludD52KG4pOwogICAgc2V0PHBhaXI8aW50LGludD4+cG9zOwogICAgcGFpcjxpbnQsaW50PnA7CiAgICBmb3IoaT0wO2k8bjtpKyspICAgICAgICBjaW4+PnZbaV0scG9zLmluc2VydCh7LXZbaV0saX0pOwogICAgZm9yKGk9bi0xO2k+MDtpLS0pewogICAgICAgIHA9KnBvcy5iZWdpbigpOwogICAgICAgIGlmKHAuZmlyc3Q9PSgtdltpXSkpewogICAgICAgICAgICBwLnNlY29uZD1pOwogICAgICAgICAgICBwb3MuZXJhc2UocCk7CiAgICAgICAgfQogICAgICAgIGVsc2V7CiAgICAgICAgICAgIGo9cC5zZWNvbmQ7CiAgICAgICAgICAgIHBvcy5lcmFzZShwKTsKICAgICAgICAgICAgcC5maXJzdD0oLXZbaV0pO3Auc2Vjb25kPWk7CiAgICAgICAgICAgIHBvcy5lcmFzZShwKTsKICAgICAgICAgICAgc3dhcCh2W2pdLHZbaV0pOwogICAgICAgICAgICBhbnMrKzsKICAgICAgICAgICAgcG9zLmluc2VydCh7LXZbal0san0pOwogICAgICAgIH0KICAgIH0KICAgIGNvdXQ8PGFuczsKICAgIGNvdXQ8PCJcbiI7Cn0KCmludCBtYWluKCkKewogICAgaW9zOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgY2luLnRpZShudWxscHRyKTsKICAgIGludCB0PTE7CiAgICB3aGlsZSh0LS0pICAgICAgcnVuX2Nhc2UoKTsKICAgIHJldHVybiAwOwp9