#include <bits/stdc++.h>
using namespace std;
const int maxn = 102;
int n, a[maxn], mn = 1, mx = 1;
void inp() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
}
void work() {
  for (int i = 1; i <= n; ++i) {
    if (a[i] <= a[mn]) mn = i;
    if (a[i] > a[mx]) mx = i;
  }
}
void out() {
  if (mx > mn)
    cout << mx - 1 + n - mn - 1;
  else
    cout << mx - 1 + n - mn;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  inp();
  work();
  out();
  return 0;
}
