#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, r;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  int large = arr[0];
  int pos = 0;
  for (int j = 1; j < n; j++) {
    if (arr[j] > large) {
      large = arr[j];
      pos = j;
    }
  }
  int temp;
  for (int k = pos; k > 0; k--) {
    temp = arr[k];
    arr[k] = arr[k - 1];
    arr[k - 1] = temp;
  }
  r = pos;
  int small = arr[n - 1];
  pos = n - 1;
  for (int j = n - 2; j > 0; j--) {
    if (arr[j] < small) {
      small = arr[j];
      pos = j;
    }
  }
  r = r + n - 1 - pos;
  cout << r;
  return 0;
}
