#include <bits/stdc++.h>
int main() {
  int n, i;
  scanf("%d", &n);
  int array[n];
  for (i = 0; i < n; i++) {
    scanf("%d", &array[i]);
  }
  int min = 9999999, max = 0, count;
  for (i = 0; i < n; i++) {
    if (array[i] < min) {
      min = array[i];
    }
    if (array[i] > max) {
      max = array[i];
    }
  }
  int maxIndex, minIndex;
  for (i = 0; i < n; i++) {
    if (array[i] == max) {
      maxIndex = i;
      break;
    }
  }
  for (i = n - 1; i >= 0; i--) {
    if (array[i] == min) {
      minIndex = i;
      break;
    }
  }
  int maxDistance, minDistance;
  int swapCount = 0;
  for (i = maxIndex; i > 0; i--) {
    swapCount++;
    int temp = array[i];
    array[i] = array[i - 1];
    array[i - 1] = temp;
  }
  for (i = 0; i < n; i++) {
    if (array[i] == max) {
      maxIndex = i;
      break;
    }
  }
  for (i = n - 1; i >= 0; i--) {
    if (array[i] == min) {
      minIndex = i;
      break;
    }
  }
  for (i = minIndex; i < n - 1; i++) {
    swapCount++;
    int temp = array[i];
    array[i] = array[i + 1];
    array[i + 1] = temp;
  }
  printf("%d", swapCount);
}
