#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int i, a, MAX = 0, MIN = 101, max_index, min_index;
  for (i = 0; i < n; i++) {
    scanf("%d", &a);
    if (a > MAX) {
      MAX = a;
      max_index = i;
    }
    if (a <= MIN) {
      MIN = a;
      min_index = i;
    }
  }
  if (max_index > min_index) min_index += 1;
  printf("%d", max_index + n - 1 - min_index);
  return 0;
}
