#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int max = 0, min = 0, imax, imin;
  for (int i = 0; i < n; i++) {
    int value;
    cin >> value;
    if (i == 0) {
      max = value;
      min = value;
      imax = 0;
      imin = 0;
    } else {
      if (value > max) {
        max = value;
        imax = i;
      }
      if (value <= min) {
        min = value;
        imin = i;
      }
    }
  }
  if (imin > imax)
    cout << (imax + n - 1 - imin) << endl;
  else
    cout << imax + n - 2 - imin << endl;
}
