#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, min1, max1;
  cin >> x;
  int* asl = new int[x];
  int* fake = new int[x];
  for (int i = 0; i < x; i++) {
    cin >> asl[i];
    fake[i] = asl[i];
  }
  sort(fake, fake + x);
  for (int i = x - 1; i >= 0; i--) {
    if (asl[i] == fake[0]) {
      min1 = i;
      break;
    }
  }
  for (int i = 0; i < x; i++) {
    if (asl[i] == fake[x - 1]) {
      max1 = i;
      break;
    }
  }
  if (max1 > min1)
    cout << ((max1 - 1) + (x - min1)) - 1;
  else
    cout << (max1 - 1) + (x - min1);
  return 0;
}
