#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool cheak(vector<int> v){
  for(int i=0;i<v.size();i++){
    if(v[i] != i+1) return false;
  }
  return true;
}
int main(){
  int N;
  while(cin >> N && N){
    bool judge = true;
    int now = 0;
    vector<int> v(N);
    for(int i = 0; i < N ; i++ ){
      cin >> v[i];
    }

    while( !cheak(v) && now <= 10000 ){
      now++;
      for(int i = 0; i < v.size() ; i++ ) v[i]--;
      v.push_back(v.size());
      v.erase(remove(v.begin(),v.end(),0),v.end());
    }
    cout << ( now > 10000 ? -1 : now ) << endl;
  }
}