#include <bits/stdc++.h>
using namespace std;
int main() {
  int sz, a, mx = -1, mxp, mn = 999, mnp, i, j;
  cin >> sz;
  int x[sz];
  for (i = 0; i < sz; i++) {
    cin >> x[i];
    if (x[i] > mx) {
      mx = x[i];
      mxp = i;
    }
    if (x[i] <= mn) {
      mn = x[i];
      mnp = i;
    }
  }
  if (mxp > mnp) mnp++;
  a = mxp + (sz - 1) - mnp;
  cout << a << '\n';
  return 0;
}
