#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int mx = *max_element(v.begin(), v.end());
  int mn = *min_element(v.begin(), v.end());
  int ind1 = 0, ind2 = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] == mx && ind1 == 0)
      ind1 = i + 1;
    else if (v[i] == mn)
      ind2 = i + 1;
  }
  ind2--;
  ind1--;
  if (ind1 > ind2) ind2++;
  long long result = ind1 + n - ind2 - 1;
  cout << result;
}
