#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  int max_index, min_index;
  int max = -100000, min = 100000;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] > max) {
      max = arr[i];
      max_index = i;
    }
    if (arr[i] <= min) {
      min = arr[i];
      min_index = i;
    }
  }
  if (min_index > max_index) {
    cout << (n - 1 - min_index) + (max_index);
  } else {
    cout << (n - 1 - min_index) + (max_index)-1;
  }
  return 0;
}
