#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int x[n], mi = INT_MAX, ma = INT_MIN, mii, mai;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    if (x[i] <= mi) {
      mii = i;
      mi = x[i];
    }
    if (x[i] > ma) {
      mai = i;
      ma = x[i];
    }
  }
  int diff = (n - 1 - mii) + (mai);
  if (mai > mii) diff--;
  cout << diff << endl;
  return 0;
}
