#include <bits/stdc++.h>
using namespace std;
int n;
int a[100010];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = n - 1; i > 0; i--) {
    if (a[i - 1] > a[i]) {
      cout << i << endl;
      exit(0);
    }
  }
  cout << 0 << endl;
}
