#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e12;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  long long int a[n];
  vector<pair<long long int, long long int> > vect;
  multiset<long long int> mset;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    vect.push_back(make_pair(a[i], i));
    mset.insert(a[i]);
  }
  sort(vect.begin(), vect.end());
  long long int ctr = 0ll;
  for (int i = 0; i < n; i++) {
    long long int val = vect[i].first;
    auto itr = mset.upper_bound(val);
    if (itr != mset.end()) {
      ctr++;
      mset.erase(itr);
    } else
      mset.erase(mset.begin());
  }
  cout << ctr << endl;
}
