#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int mx = -1;
  int mn = 101;
  int r, l;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (mx < a[i]) {
      mx = a[i];
      r = i + 1;
    }
    if (mn >= a[i]) {
      mn = a[i];
      l = i + 1;
    }
  }
  int cnt = 0;
  if (r > l) {
    cnt = r + n - l - 2;
  } else {
    cnt = r + n - l - 1;
  }
  cout << cnt;
}
