#include <bits/stdc++.h>
const int maxn = 110;
int a[maxn];
int main() {
  int cntn, cntm;
  int n, minn = 110, maxx = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] > maxx) maxx = a[i], cntn = i;
    if (a[i] <= minn) minn = a[i], cntm = i;
  }
  if (cntn >= cntm)
    printf("%d", cntn + n - cntm - 2);
  else
    printf("%d", cntn + n - cntm - 1);
  return 0;
}
