#include <bits/stdc++.h>
using namespace std;
int count_swaps_needed(int soldiers, int* heights);
int main() {
  int soldiers;
  cin >> soldiers;
  int* heights = new int[soldiers];
  for (int s = 0; s < soldiers; s++) {
    cin >> heights[s];
  }
  int swaps_needed = count_swaps_needed(soldiers, heights);
  cout << swaps_needed;
}
int count_swaps_needed(int soldiers, int* heights) {
  int max_ht = INT_MIN;
  int max_pos = 0;
  int min_ht = INT_MAX;
  int min_pos = soldiers - 1;
  for (int s = 0; s < soldiers; s++) {
    if (heights[s] > max_ht) {
      max_ht = heights[s];
      max_pos = s;
    }
    if (heights[s] <= min_ht) {
      min_ht = heights[s];
      min_pos = s;
    }
  }
  return max_pos + (soldiers - min_pos - 1) - (max_pos > min_pos);
}
