#include <bits/stdc++.h>
using namespace std;
int maxnumb(int *a, int n, int &indmax) {
  int maxik = a[0];
  for (int i = 0; i < n; i++) {
    if (a[i] > maxik) {
      maxik = max(maxik, a[i]);
      indmax = i;
    }
  }
  return maxik;
}
int minnumb(int *a, int n, int &indmin) {
  int minik = a[0];
  for (int i = 0; i < n; i++) {
    if (a[i] <= minik) {
      minik = min(minik, a[i]);
      indmin = i;
    }
  }
  return minik;
}
int main() {
  int a[100], maxik, minik;
  int indmax, indmin, k = 0;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  maxik = maxnumb(a, n, indmax);
  for (int i = indmax; i > 0; i--) {
    swap(a[i - 1], a[i]);
    k++;
  }
  minik = minnumb(a, n, indmin);
  for (int i = indmin; i < n - 1; i++) {
    swap(a[i + 1], a[i]);
    k++;
  }
  cout << k << endl;
  return 0;
}
