#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[100], max, max1, min, min1;
  cin >> n;
  cin >> a[1];
  max = a[1];
  min = a[1];
  min1 = 1;
  max1 = 1;
  for (int i = 2; i <= n; i++) {
    cin >> a[i];
    if (max <= a[i]) {
      if (max == a[i])
        max = a[i];
      else {
        max = a[i];
        max1 = i;
      }
    }
    if (min >= a[i]) {
      min = a[i];
      min1 = i;
    }
  }
  if (max1 < min1)
    cout << (n - min1) + (max1 - 1) << endl;
  else
    cout << ((n - min1) + (max1 - 1)) - 1 << endl;
  return 0;
}
