#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[100];
  int n, max_loc = 0, min_loc = 0;
  int i;
  cin >> n;
  int mi, ma;
  for (i = 0; i < n; i++) cin >> a[i];
  ma = a[0];
  mi = a[0];
  for (i = 0; i < n; i++) {
    if (a[i] > ma) {
      ma = a[i];
      max_loc = i;
    }
    if (a[i] <= mi) {
      mi = a[i];
      min_loc = i;
    }
  }
  int t = 0;
  if (max_loc > min_loc) {
    min_loc++;
    n--;
    t = max_loc + n - min_loc;
  } else {
    n--;
    t = max_loc + n - min_loc;
  }
  cout << t;
  return 0;
}
