#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int mini = 10000, maxi = 0, minIndex, maxIndex;
  int arr[101];
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    if (arr[i] <= mini) {
      mini = arr[i];
      minIndex = i;
    }
    if (arr[i] > maxi) {
      maxi = arr[i];
      maxIndex = i;
    }
  }
  if (maxIndex < minIndex)
    cout << maxIndex + n - 1 - minIndex;
  else
    cout << maxIndex + n - 1 - minIndex - 1;
}
