#include <bits/stdc++.h>
long k, a[10000000], n, nM = -1, nm = 101, pm, pM, s = 0;
int main() {
  scanf("%ld", &n);
  for (k = 0; k < n; k++) {
    scanf("%ld", &a[k]);
    if (a[k] <= nm) {
      nm = a[k];
      pm = k + 1;
    }
    if (a[k] > nM) {
      nM = a[k];
      pM = k + 1;
    }
  }
  s = n - pm + pM - 1;
  if (pM > pm) s--;
  printf("%ld\n", s);
  getchar();
  getchar();
}
