#include <bits/stdc++.h>
int main() {
  int n, ans, s, g, c, r, f, d;
  scanf("%d", &n);
  int a[n];
  for (c = 1; c <= n; c++) {
    scanf("%d", &a[c]);
    if (c == 1) {
      g = a[c];
      d = c;
      s = a[c];
      f = c;
    }
    if (g < a[c]) {
      g = a[c];
      d = c;
    }
    if (s >= a[c]) {
      s = a[c];
      f = c;
    }
  }
  if (f < d)
    ans = d - 1 + n - f - 1;
  else if (f > d)
    ans = d - 1 + n - f;
  printf("%d", ans);
  return 0;
}
