#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; ++i) cin >> h[i];
  int mx = 0, mn = 0;
  for (int i = 1; i < n; ++i) {
    if (h[i] > h[mx]) mx = i;
    if (h[i] <= h[mn]) mn = i;
  }
  cerr << "("
       << "mx"
       << ", "
       << "mn"
       << ") = (" << mx << ", " << mn << ")\n";
  cerr << "("
       << "h[mx]"
       << ", "
       << "h[mn]"
       << ") = (" << h[mx] << ", " << h[mn] << ")\n";
  int ans = (mx - 0) + (n - 1 - mn);
  if (mx < mn)
    cout << ans << '\n';
  else
    cout << ans - 1 << '\n';
  return 0;
}
