#include <bits/stdc++.h>
int dr[] = {2, 2, -2, -2, 1, -1, 1, -1};
int dc[] = {1, -1, 1, -1, 2, 2, -2, -2};
int dr1[] = {0, 0, 0, 1, 1, 1, -1, -1, -1};
int dc1[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
int dr2[] = {0, 0, 1, -1};
int dc2[] = {1, -1, 0, 0};
using namespace std;
int main() {
  long long int n, i, j;
  while (cin >> n) {
    long long int a[n + 5];
    for (long long int i = 1; i < n + 1; i++) {
      scanf("%lld", &a[i]);
    }
    map<long long int, long long int> mp;
    long long int cn = 0;
    sort(a + 1, a + n + 1);
    for (i = 1; i <= n; i++) {
      if (mp[a[i]] == 0) mp[a[i]] = ++cn;
    }
    long long int fr[cn + 5];
    memset(fr, 0, sizeof(fr));
    for (i = 1; i <= n; i++) {
      long long int p = mp[a[i]];
      fr[p]++;
    }
    long long int ans = 0;
    for (long long int i = 1; i < n + 1; i++) a[i] = mp[a[i]];
    set<long long int> s;
    set<long long int>::iterator it;
    for (long long int i = 1; i < cn + 1; i++) s.insert(i);
    for (i = 1; i <= n; i++) {
      if (s.size() == 0) break;
      it = s.begin();
      long long int q = *it;
      if (q == a[i]) {
        s.erase(s.find(q));
        if (s.size() == 0) break;
      }
      it = s.begin();
      q = *it;
      if (q > cn) {
        break;
      }
      fr[q]--;
      ans++;
      if (fr[q] == 0) {
        s.erase(s.find(q));
        if (s.size() == 0) break;
      }
      if (fr[cn] == 0) break;
    }
    cout << ans << endl;
  }
  return 0;
}
