#include <bits/stdc++.h>
using namespace std;
void swap(int r, int s) {
  int temp = r;
  r = s;
  s = temp;
  return;
}
char to_upper(char a) { return a - 32; }
char to_lower(char a) { return a + 32; }
bool isPrime(int x) {
  for (int i = 2; i <= x / 2; i++) {
    if (x % i == 0) return false;
  }
  return true;
}
int main() {
  int size;
  cin >> size;
  int *list = new int[size];
  int number;
  for (int i = 0; i < size; i++) cin >> list[i];
  int maxIndex = 0, minIndex = 0;
  for (int i = 0; i < size; i++) {
    if (list[i] > list[maxIndex])
      maxIndex = i;
    else if (list[i] <= list[minIndex])
      minIndex = i;
  }
  if (minIndex > maxIndex) {
    number = (maxIndex) + (size - minIndex - 1);
  } else {
    number = (maxIndex) + (size - minIndex - 2);
  }
  cout << number;
  return 0;
}
