#include <bits/stdc++.h>
using namespace std;
int c[100010];
int lowbit(int x) { return x & (-x); }
void add(int x) {
  for (int i = x; i < 100010; i += lowbit(i)) c[i] += 1;
}
int sum(int x) {
  int ret = 0;
  for (int i = x; i > 0; i -= lowbit(i)) ret += c[i];
  return ret;
}
int main() {
  int n;
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; i++) {
      scanf("%d", &c[i]);
    }
    if (n == 1) {
      printf("0\n");
      continue;
    }
    int num = 0;
    for (int i = n - 2; i >= 0; i--)
      if (c[i + 1] < c[i]) {
        num = i + 1;
        break;
      }
    printf("%d\n", num);
  }
  return 0;
}
