#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int *h = new int[n], *p = h;
  cin >> *p;
  int maxele = *p, minele = *p;
  int maxidx = 0, minidx = 0;
  int i = 1;
  while (i < n) {
    ++i;
    ++p;
    cin >> *p;
    if (*p > maxele) {
      maxele = *p;
      maxidx = p - h;
    }
    if (*p <= minele) {
      minele = *p;
      minidx = p - h;
    }
  }
  int res = maxidx + n - minidx - 1;
  if (maxidx > minidx) {
    res -= 1;
  }
  cout << res << endl;
  delete[] h;
  return 0;
}
