#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 max = 0, maxpos, min = 1000, minpos;
  for (int i = 0; i < n; i++) {
    if (arr[i] > max) {
      max = arr[i];
      maxpos = i;
    }
  }
  int temp;
  for (int i = maxpos; i > 0; i--) {
    if (arr[i] > arr[i - 1]) {
      temp = arr[i];
      arr[i] = arr[i - 1];
      arr[i - 1] = temp;
    }
  }
  for (int i = n - 1; i > 0; i--) {
    if (arr[i] < min) {
      min = arr[i];
      minpos = i;
    }
  }
  cout << maxpos + n - 1 - minpos;
}
