#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 1;
const int N = 1e3 + 1;
long long n, a[MAXN], ix, iy;
int main() {
  cin >> n;
  for (int i = 1, mn = INF, mx = -INF; i <= n; i++) {
    cin >> a[i];
    if (mn >= a[i]) mn = a[i], iy = i;
    if (mx < a[i]) mx = a[i], ix = i;
  }
  long long ans = ix - 1 + n - iy;
  if (iy < ix) ans--;
  cout << ans;
  return 0;
}
