#include <bits/stdc++.h>
using namespace std;
int minimum(int t[], int n) {
  int indmin = 0;
  for (int i = 1; i < n; i++) {
    if (t[i] <= t[indmin]) {
      indmin = i;
    }
  }
  return indmin;
}
int maximum(int t[], int n) {
  int indmax = n - 1;
  for (int i = n - 2; i >= 0; i--) {
    if (t[i] >= t[indmax]) {
      indmax = i;
    }
  }
  return indmax;
}
int main() {
  int n;
  cin >> n;
  int t[n];
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }
  if (maximum(t, n) < minimum(t, n)) {
    cout << maximum(t, n) + n - 1 - minimum(t, n);
  } else if (maximum(t, n) > minimum(t, n)) {
    cout << n - 1 - minimum(t, n) + maximum(t, n) - 1;
  } else {
    cout << "0";
  }
}
