#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int c = 0;
  for (int i = 0; i < n; i++) cin >> a[i];
  int pos1 = INT_MIN, pos2 = INT_MAX;
  int x = *min_element(a.begin(), a.end());
  int y = *max_element(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    if (a[i] == x) {
      pos1 = max(pos1, i);
    }
    if (a[i] == y) {
      pos2 = min(pos2, i);
    }
  }
  if (pos1 < pos2) {
    cout << pos2 + (n - 1 - pos1) - 1 << endl;
  } else if (pos1 > pos2) {
    cout << pos2 + (n - 1 - pos1) << endl;
  } else
    cout << 0 << endl;
  return 0;
}
