#include <bits/stdc++.h>
using namespace std;
void swap(int *a, int *b) {
  int t = *a;
  *a = *b;
  *b = t;
}
void disp(int *a, int n) {
  for (int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}
int main() {
  int num, b = 0, s = 1000000;
  cin >> num;
  int h[num], bi, si;
  for (int i = 0; i < num; i++) {
    cin >> h[i];
    if (h[i] > b) {
      b = h[i];
      bi = i;
    }
    if (h[i] < s) {
      s = h[i];
      si = i;
    }
  }
  int k = bi, count = 0;
  while (h[0] != b) {
    swap(h[k], h[k - 1]);
    count++;
    k--;
  }
  for (int i = 0; i < num; i++) {
    if (h[i] == s && si <= i) {
      si = i;
    }
  }
  int j = si;
  while (h[num - 1] != s) {
    swap(h[j + 1], h[j]);
    count++;
    j++;
  }
  cout << count << endl;
  return 0;
}
