#include <bits/stdc++.h>
long long int val[1000004] = {0};
using namespace std;
long long getmul(long long n) {
  long long int k{0};
  while (n > 0) {
    k += n % 10;
    n = n / 10;
  }
  return k;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  int x = max_element(arr, arr + n) - arr;
  int y = min_element(arr, arr + n) - arr;
  for (int i = n - 1; i >= 0; i--) {
    if (arr[i] == arr[y]) {
      y = i;
      break;
    }
  }
  if (x < y) {
    cout << x + n - y - 1 << "\n";
  } else {
    cout << x + n - y - 2 << "\n";
  }
  return 0;
}
