#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 2e18;
const ll MOD = 1e9 + 7;

mt19937 rnd(time(0));



int main() {
//    std::ios_base::sync_with_stdio(0);
//    std::cin.tie(0); std::cout.tie(0);
    int n;
    cin >> n;
    vector <ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll mx = -INF, mn = INF;
    int pos_mx = -1, pos_mn = -1;
    for (int i = 0; i < n; i++) {
        if (a[i] > mx) {
            mx = a[i];
            pos_mx = i;
        }
        if (a[i] <= mn) {
            mn = a[i];
            pos_mn = i;
        }
    }
    int ans = pos_mx + (n - pos_mn - 1);
    if (pos_mx > pos_mn) {
        ans--;
    }
    cout << ans;
    return 0;
}
