#include <bits/stdc++.h>
int main(void) {
  int N, height, tall = 0, tallPos, small = 101, smallPos, sec, i;
  scanf("%d", &N);
  for (i = 0; i < N; i++) {
    scanf("%d", &height);
    if (height > tall) {
      tall = height;
      tallPos = i;
    }
    if (height <= small) {
      small = height;
      smallPos = i;
    }
  }
  sec = (tallPos + ((N - 1) - smallPos));
  if (tallPos > smallPos) sec--;
  printf("%d\n", sec);
  return 0;
}
