#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[105], n, araf, zeft;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int min, max;
  min = max = a[0];
  for (int i = 0; i < n; i++) {
    if (a[i] <= min) {
      min = a[i];
      araf = i;
    }
  }
  int c = 0;
  for (int i = araf; a[n - 1] != min; i++) {
    swap(a[i], a[i + 1]);
    c++;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] > max) {
      max = a[i];
      zeft = i;
    }
  }
  for (int i = zeft; a[0] != max; i--) {
    swap(a[i], a[i - 1]);
    c++;
  }
  cout << c;
}
