#include <bits/stdc++.h>
using namespace std;
const int MAXn = 100 + 17;
int n;
int arr[MAXn];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  int min = 100 + 17, max = 0, jamin = 0, jamax = 0;
  for (int i = n; i >= 1; i--) {
    if (arr[i] < min) {
      min = arr[i];
      jamin = i;
    }
    if (arr[n - i + 1] > max) {
      max = arr[n - i + 1];
      jamax = n - i + 1;
    }
  }
  if (jamin < jamax)
    cout << n - jamin + jamax - 1 - 1 << endl;
  else
    cout << n - jamin + jamax - 1 << endl;
  return 0;
}
