#include <bits/stdc++.h>
int main() {
  int n, a, i, max = 0, min = 101, x, y, z;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a);
    if (a > max) {
      max = a;
      x = i;
    }
    if (a <= min) {
      min = a;
      y = i;
    }
  }
  z = x - 1 + n - y;
  if (x > y) z--;
  printf("%d", z);
}
