#include <bits/stdc++.h>
using namespace std;
int n, i, p, q = 99, x, a, b;
int main() {
  for (cin >> n; i++ < n;)
    cin >> x, x > p ? p = x, b = i : 0, x <= q ? q = x, a = i : 0;
  cout << b + n - a - 1 - (b > a);
}
