#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, me = 1, ma = 1;
  cin >> n;
  int sol[n + 1];
  for (i = 1; i <= n; i++) {
    cin >> sol[i];
    if (sol[i] > sol[ma])
      ma = i;
    else if (sol[me] >= sol[i])
      me = i;
  }
  i = (ma - 1) + (n - me);
  if (ma > me)
    cout << i - 1 << endl;
  else
    cout << i << endl;
}
