#include <bits/stdc++.h>
using namespace std;
int main() {
  int maxh = 0, leasth = 0, maxindex, leastindex;
  int n, d;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> d;
    if (d <= leasth || leasth == 0) {
      leasth = d;
      leastindex = i;
    }
    if (d > maxh) {
      maxh = d;
      maxindex = i;
    }
  }
  cout << (n - leastindex) + (maxindex - 1) +
              ((maxindex > leastindex) ? -1 : 0);
  return 0;
}
