#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t;
  cin >> n >> t;
  int min_t(t), max_t(t), min_i(0), max_i(0);
  for (int i = 1; i < n; ++i) {
    cin >> t;
    if (t > max_t) {
      max_t = t;
      max_i = i;
    }
    if (t <= min_t) {
      min_t = t;
      min_i = i;
    }
  }
  cout << max_i + (n - 1 - min_i) - (min_i < max_i ? 1 : 0);
  return 0;
}
