#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int *a = new int[n];
  int max = 0, posMax = -1, min = 200, posMin = -1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > max) {
      max = a[i];
      posMax = i;
    }
    if (a[i] <= min) {
      min = a[i];
      posMin = i;
    }
  }
  if (posMax < posMin) {
    cout << posMax + (n - posMin - 1);
  } else {
    cout << posMax + (n - posMin - 1) - 1;
  }
  return 0;
}
