#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int arrs[n];
  for (int i = 0; i < n; i++) {
    arrs[i] = arr[i];
  }
  sort(arrs, arrs + n);
  int count = 0;
  int low = arrs[0];
  int high = arrs[n - 1];
  int lowpos, highpos;
  for (int i = 0; i < n; i++) {
    if (arr[i] == low) {
      lowpos = i;
    }
  }
  while (arr[n - 1] != low) {
    swap(arr[lowpos], arr[lowpos + 1]);
    lowpos++;
    count++;
  }
  for (int i = 0; i < n; i++) {
    if (arr[i] == high) {
      highpos = i;
      break;
    }
  }
  while (arr[0] != high) {
    swap(arr[highpos - 1], arr[highpos]);
    highpos--;
    count++;
  }
  cout << count;
}
