#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, a[100000];
  scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    scanf("%d", &a[i]);
  }
  int index, flag;
  for (int i = t - 2; i >= 0; i--) {
    if (a[i] > a[i + 1]) {
      index = i;
      printf("%d\n", (index + 1));
      flag = 0;
      break;
    } else {
      flag = 1;
      index = i;
    }
  }
  if (flag == 1) printf("%d\n", 0);
  return 0;
}
