#include <bits/stdc++.h>
void swap(int *a, int *b) {
  int tmp = *a;
  *a = *b;
  *b = tmp;
}
int main() {
  int n;
  scanf("%d", &n);
  int *arr = (int *)malloc(n * sizeof(int));
  int min;
  int max;
  scanf("%d", arr);
  min = *arr;
  max = *arr;
  for (int i = 1; i < n; i++) {
    scanf("%d", arr + i);
    if (arr[i] > max) max = arr[i];
    if (arr[i] < min) min = arr[i];
  }
  int index_min, index_max;
  for (int i = 0; i < n; i++) {
    if (arr[i] == min) index_min = i;
  }
  int num = 0;
  for (int i = index_min; i < n - 1; i++) {
    swap(arr + i, arr + i + 1);
    num++;
  }
  for (int i = 0; i < n; i++) {
    if (arr[i] == max) {
      index_max = i;
      break;
    }
  }
  for (int i = index_max; i > 0; i--) {
    swap(arr + i, arr + i - 1);
    num++;
  }
  printf("%d", num);
  return 0;
}
