#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
int main(int argc, char const* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int a[101];
  for (int i = 0; i < n; i++) cin >> a[i];
  int min, max, min_index, max_index;
  min = a[0];
  min_index = 0;
  max = a[0];
  max_index = 0;
  for (int i = 0; i < n; i++) {
    if (min >= a[i]) {
      min = a[i];
      min_index = i;
    }
    if (max < a[i]) {
      max = a[i];
      max_index = i;
    }
  }
  if (min_index < max_index) {
    min_index = (n - 1) - min_index;
    cout << (min_index + max_index - 1) << endl;
  } else {
    min_index = (n - 1) - min_index;
    cout << (min_index + max_index) << endl;
    return 0;
  }
}
