#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[105], ma = 0, mi = 110, maxi, mini, tc;
  cin >> tc;
  for (int i = 0; i < tc; i++) {
    cin >> a[i];
    if (a[i] > ma) {
      ma = a[i];
      maxi = i;
    }
    if (a[i] <= mi) {
      mi = a[i];
      mini = i;
    }
  }
  if (maxi > mini) {
    mini++;
  }
  cout << maxi + (tc - 1) - mini << endl;
}
