#include <bits/stdc++.h>
#pragma comment(linker, "/stack:16000000")
using namespace std;
const double eps = 1e-10;
int sqr(int a) { return a * a; }
vector<int> v;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    v.push_back(x);
  }
  int mn = v[v.size() - 1];
  for (int i = n - 2; i >= 0; --i) {
    if (v[i] > mn) {
      cout << i + 1 << endl;
      return 0;
    }
    mn = std::min(mn, v[i]);
  }
  cout << 0 << endl;
  return 0;
}
