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