#include <bits/stdc++.h>
int main() {
  int p[200], i, min = 200, max = -100, x, y, n = 0, pre = 0, res = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
    if (p[i] > max) {
      max = p[i];
      x = i;
    }
    if (p[i] < min) {
      min = p[i];
      y = i;
    }
  }
  for (i = 1; i <= n; i++) {
    if (max == p[i] && i < x) {
      x = i;
    }
    if (min == p[i] && i > y) {
      y = i;
    }
  }
  if (x > y) {
    pre = n - x;
    pre++;
    res += n - pre;
    pre = n - y;
    res += pre;
    res--;
    printf("%d", res);
  } else {
    pre = n - x;
    pre++;
    res += n - pre;
    pre = n - y;
    res += pre;
    printf("%d", res);
  }
}
