#include <bits/stdc++.h>
using namespace std;
int n, a[105], cnt, mxhi, mnhi;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  mxhi = 0;
  mnhi = 0;
  for (int i = 0; i < n; ++i) {
    if (a[mxhi] < a[i]) mxhi = i;
  }
  while (true) {
    if (mxhi == 0) break;
    swap(a[mxhi], a[mxhi - 1]);
    mxhi--;
    cnt++;
  }
  for (int i = 0; i < n; ++i)
    if (a[mnhi] >= a[i]) mnhi = i;
  while (true) {
    if (mnhi == n - 1) break;
    swap(a[mnhi], a[mnhi + 1]);
    mnhi++;
    cnt++;
  }
  cout << cnt;
}
