#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
    cout << "\n";
  }
  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}
void solve() {
  int n;
  cin >> n;
  std::vector<int> v(n);
  int maximum = numeric_limits<int>::min(),
      minimum = numeric_limits<int>::max();
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    maximum = max(maximum, v[i]);
    minimum = min(minimum, v[i]);
  }
  int firstmax, lastmin;
  for (int i = 0; i < n; ++i) {
    if (v[i] == maximum) {
      firstmax = i;
      break;
    }
  }
  for (int i = n - 1; i >= 0; --i) {
    if (v[i] == minimum) {
      lastmin = i;
      break;
    }
  }
  int ans;
  if (firstmax < lastmin) {
    ans = firstmax + (n - 1 - lastmin);
  } else {
    ans = firstmax + (n - 1 - lastmin) - 1;
  }
  cout << ans;
}
