#include <bits/stdc++.h>
using namespace std;
long long ele;
int main() {
  long long n;
  scanf("%lld", &n);
  long long arr[n + 2];
  long long ma = LONG_LONG_MIN, mi = LONG_LONG_MAX;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &arr[i]);
    ma = max(ma, arr[i]);
    mi = min(mi, arr[i]);
  }
  long long posboro = 0;
  for (int i = 1; i <= n; i++) {
    if (arr[i] == ma) {
      posboro = i;
      break;
    }
  }
  long long posc;
  for (int i = n; i > 0; i--) {
    if (arr[i] == mi) {
      posc = i;
      break;
    }
  }
  if (posboro > posc) {
    long long sum = 0;
    sum += (n - posc);
    sum += posboro - 2;
    cout << sum << endl;
  } else {
    long long sum = 0;
    sum += (n - posc);
    sum += posboro - 1;
    cout << sum << endl;
  }
  return 0;
}
