#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int& x : v) cin >> x;
  int min = 1e9, max = -1;
  int minindex, maxindex;
  for (int i = 0; i < n; i++) {
    if (v[i] > max) {
      max = v[i];
      maxindex = i;
    }
    if (v[i] <= min) {
      min = v[i];
      minindex = i;
    }
  }
  int ret = n - 1 - minindex + maxindex;
  if (minindex < maxindex) ret--;
  cout << ret << endl;
}
