#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = n - 2; i >= 0; i--)
    if (arr[i] > arr[i + 1]) {
      cout << i + 1;
      return 0;
    }
  cout << 0;
  return 0;
}
