#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a;
  vector<int> v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }
  vector<int> v1;
  v1 = v;
  sort(v.begin(), v.end());
  int maxh = v[n - 1], minh = v[0];
  int maxi, mini, ans;
  int flag = 0;
  for (int i = 0; i < n; i++) {
    if (v1[i] == maxh && flag == 0) {
      flag = 1;
      maxi = i;
    }
    if (v1[i] == minh) mini = i;
  }
  if (mini > maxi)
    ans = maxi + (n - 1 - mini);
  else
    ans = maxi + (n - 1 - mini) - 1;
  cout << ans << "\n";
  return 0;
}
