#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
  int n;
  string str;
  stringstream ss;
  getline(cin, str);
  ss << str;
  ss >> n;
  ss.clear();
  getline(cin, str);
  ss << str;
  int i = 0;
  while (ss >> a[i]) i++;
  for (int i = n - 1; i > 0; i--) {
    if (a[i - 1] > a[i]) {
      cout << i << endl;
      return 0;
    }
  }
  cout << 0 << endl;
}
