#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++) cin >> h[i];
  int time = 0;
  int min = h.size() - 1, max = 0;
  for (int i = 0; i < n; i++) {
    if (h[i] > h[max]) max = i;
  }
  int temp;
  for (int i = max; i > 0; i--) {
    temp = h[i];
    h[i] = h[i - 1];
    h[i - 1] = temp;
    time++;
  }
  for (int i = h.size() - 1; i >= 0; i--) {
    if (h[i] < h[min]) min = i;
  }
  for (int i = min; i < h.size() - 1; i++) {
    temp = h[i];
    h[i] = h[i + 1];
    h[i + 1] = temp;
    time++;
  }
  cout << time;
  return 0;
}
