#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, big, small, counter = 0, y, b = 0;
  cin >> x;
  int a[x];
  for (int i = 0; i < x; i++) {
    cin >> y;
    a[i] = y;
  }
  big = max_element(a, a + x) - a;
  for (int i = 0; i < big; i++) {
    swap(a[big - i], a[big - 1 - i]);
    counter++;
  }
  small = min_element(a, a + x) - a;
  for (int i = 0; i < x; i++) {
    if (a[i] == a[small]) small = i;
  }
  for (int i = x - 1; i > small; i--, b++) {
    swap(a[small + b], a[small + 1 + b]);
    counter++;
  }
  cout << counter;
}
