#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int mini = 1000, maxi = -1000;
  int mi_index, ma_index;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] <= mini) {
      mini = a[i];
      mi_index = i + 1;
    }
    if (a[i] > maxi) {
      maxi = a[i];
      ma_index = i + 1;
    }
  }
  int c = ma_index - 1;
  int b = n - mi_index;
  if (mi_index < ma_index) b--;
  cout << c + b;
  return 0;
}
