#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a;
  vector<int> ind(n + 1);
  for (long long i = 0; i < n; ++i) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
    ind[tmp] = i;
  }
  int offset = 0;
  for (int i = n; i >= 1; i--) {
    if (ind[i] < a[ind[i]] - 1 + offset) offset++;
  }
  cout << offset << endl;
  return 0;
}
