#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  int in[a];
  int min = 100;
  int max = 0;
  for (int b = 0; b < a; b++) {
    cin >> in[b];
    if (in[b] > max) {
      max = in[b];
    }
    if (in[b] < min) {
      min = in[b];
    }
  }
  int min1, max1;
  for (int c = 0; c < a; c++) {
    if (in[c] == max) {
      max1 = c;
      break;
    }
  }
  for (int d = a - 1; d >= 0; d--) {
    if (min == in[d]) {
      min1 = d;
      break;
    }
  }
  int out = max1 + a - 1 - min1;
  if (min1 >= max1) {
    cout << out;
  } else {
    cout << out - 1;
  }
}
