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