#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, moves = 0;
  cin >> n;
  int soldiers[n], max = 0, min = 101, minind = 0, maxind = 0;
  for (int i = 0; i < n; i++) {
    cin >> soldiers[i];
  }
  for (int i = 0; i < n; i++) {
    if (soldiers[i] > max) {
      max = soldiers[i];
      maxind = i;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (soldiers[i] < min) {
      min = soldiers[i];
      minind = i;
    }
  }
  moves += maxind + (n - minind - 1);
  if (moves >= n) moves--;
  cout << moves;
  return 0;
}
