#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, k, t, a[110];
  cin >> n;
  int mn = 9999, mx = 0, mi, xi;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] <= mn) {
      mn = a[i];
      mi = i;
    }
    if (a[i] > mx) {
      mx = a[i];
      xi = i;
    }
  }
  int ans;
  ans = xi + (n - mi - 1);
  if (xi > mi) ans--;
  cout << ans << endl;
  return 0;
}
