#include <bits/stdc++.h>
using namespace std;
int n;
int a[200000], b[200000];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    a[n + i] = a[i];
  }
  b[0] = 1;
  for (int i = 1; i < 2 * n; ++i) {
    if (a[i] >= a[i - 1])
      b[i] = b[i - 1] + 1;
    else
      b[i] = 1;
    if (b[i] == n) {
      cout << (n - (i - b[i] + 1)) % n;
      return 0;
    }
  }
  cout << "-1";
  return 0;
}
