#include <bits/stdc++.h>
int main() {
  int n, tmp, min = 100, max = 0, minPos, maxPos;
  std::vector<int> soldats;
  std::cin >> n;
  for (int i = 0; i < n; ++i) {
    std::cin >> tmp;
    soldats.push_back(tmp);
    if (tmp > max) {
      max = tmp;
      maxPos = i;
    }
    if (tmp <= min) {
      min = tmp;
      minPos = i;
    }
  }
  if (minPos == n - 1 && maxPos == 0)
    std::cout << 0;
  else if (maxPos < minPos)
    std::cout << maxPos + (n - 1) - minPos;
  else
    std::cout << maxPos + (n - 2) - minPos;
}
