#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n, min, max, x, y, i, valmin, valmax, ans;
  cin >> n >> x;
  min = 0;
  max = 0;
  valmin = x;
  valmax = x;
  for (i = 1; i < n; i++) {
    cin >> y;
    if (y > valmax) {
      max = i;
      valmax = y;
    } else if (y <= valmin) {
      min = i;
      valmin = y;
    }
  }
  ans = max + n - 1 - min;
  if (min < max) ans--;
  cout << ans << endl;
  return 0;
}
