#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t = 0, first = 0, t1 = 0, f1 = 0, x, y, z, i;
  int numbers[100] = {};
  vector<int> v;
  cin >> n;
  for (int i = 0; i <= n - 1; i++) {
    cin >> numbers[i];
  }
  for (int i = 0; i <= n - 1; i++) {
    v.push_back(numbers[i]);
  }
  sort(v.begin(), v.end());
  for (i = 0; i <= n - 1; i++) {
    if (numbers[i] == v[n - 1]) {
      z = i;
      break;
    }
    if (numbers[i] != v[n - 1]) {
      t++;
    }
  }
  for (x = n - 1; x >= 0; x--) {
    if (numbers[x] == v[0]) {
      y = x;
      break;
    }
    if (numbers[x] != v[0]) {
      t1++;
    }
  }
  if (z > y) {
    t1 = t1 - 1;
  }
  cout << t + t1 << "\n";
}
