#include <bits/stdc++.h>
using namespace std;
int main() {
  int tests, n, minn = 1000, maxx = -9999, minl, maxl, counter = 0;
  vector<int> v;
  cin >> tests;
  for (int i = 0; i < tests; i++) {
    cin >> n;
    v.push_back(n);
  }
  for (int j = 0; j < v.size(); j++) {
    if (v[j] <= minn) {
      minn = v[j];
      minl = j;
    }
  }
  for (int i = minl; i < v.size() - 1; i++) {
    swap(v[i], v[i + 1]);
    counter++;
  }
  for (int j = 0; j < v.size(); j++) {
    if (v[j] > maxx) {
      maxx = v[j];
      maxl = j;
    }
  }
  for (int i = maxl; i > 0; i--) {
    swap(v[i], v[i - 1]);
    counter++;
  }
  cout << counter;
  return 0;
}
