#include <bits/stdc++.h>
using namespace std;
template <typename T>
void update_max(T& a, T b) {
  if (b > a) a = b;
}
template <typename T>
void update_min(T& a, T b) {
  if (b < a) a = b;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n, -1);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int max_height = INT_MIN, max_index = n - 1;
  int min_height = INT_MAX, min_index = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] >= max_height) {
      max_height = a[i];
      max_index = i;
    }
    if (a[n - i - 1] <= min_height) {
      min_height = a[n - i - 1];
      min_index = n - i - 1;
    }
  }
  if (min_index < max_index) {
    cout << max_index + (n - 1 - min_index) - 1;
  } else if (min_index > max_index) {
    cout << max_index + (n - 1 - min_index);
  } else {
    cout << 0;
  }
  cout << endl;
  return 0;
}
