#include <bits/stdc++.h>
using namespace std;
int main() {
  int num, Mheight = 0, Mnheight = INT_MAX, a, Mxpos, Mnpos;
  cin >> num;
  for (int i = 1; i <= num; i++) {
    cin >> a;
    if (Mheight < a) {
      Mheight = a;
      Mxpos = i;
    }
    if (Mnheight >= a) {
      Mnheight = a;
      Mnpos = i;
    }
  }
  int sec = Mxpos - 1;
  sec += num - Mnpos;
  if (Mxpos > Mnpos) sec--;
  cout << sec;
  return 0;
}
