#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 1e6 + 5;
long long int POWER[65];
long long int aonb(long long int a, long long int b) {
  long long int ret = 1;
  while (b) {
    if (b & 1) ret *= a;
    a *= a;
    if (ret >= MOD) ret %= MOD;
    if (a >= MOD) a %= MOD;
    b >>= 1;
  }
  return ret;
}
void precompute() {
  POWER[0] = 1;
  for (int i = 1; i < 63; i++) POWER[i] = POWER[i - 1] << 1LL;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> A(n);
  int mini = INT_MAX - 1, ii;
  int maxi = INT_MIN + 1, ai;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    if (mini >= A[i]) {
      mini = A[i];
      ii = i;
    }
    if (maxi < A[i]) {
      maxi = A[i];
      ai = i;
    }
  }
  int ans = ai + (n - ii - 1);
  if (ai > ii) {
    ans--;
  }
  cout << ans;
  return 0;
}
