#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = int(0); i < int(n); i++) {
    cin >> v[i];
  }
  int min = INT_MAX, indmin = 0;
  int max = INT_MIN, indmax = n;
  for (int i = int(0); i < int(n); i++) {
    if (v[i] < min) {
      min = v[i];
      indmin = i;
    } else if (v[i] == min) {
      if (i > indmin) indmin = i;
    }
    if (v[i] > max) {
      max = v[i];
      indmax = i;
    } else if (v[i] == max) {
      if (i < indmax) indmax = i;
    }
  }
  cout << indmax + n - (indmin + 1) - (indmin < indmax);
}
