#include<iostream>
#include<vector>
#include<cassert>
using namespace std;
#define SMIN 3
#define SMAX 1000000
#define NMIN 1
#define NMAX 100
#define BMIN 1
#define BMAX 10000
#define LIM 10000
#define TCASE 20

bool valid[SMAX+1];

bool check(vector<int> v){
  if ( v[0] != 1 ) return false;
  for ( int i = 1; i < v.size(); i++ ){
    if ( v[i-1]+1 != v[i] ) return false;
  }
  return true;
}

int simulate(vector<int> v, int sum){
  assert( SMIN <= sum && sum <= SMAX );
  //if ( !valid[sum]) return -1;
  int cnt = 0;
  while(1){
    if ( check(v) ) return cnt;
    int r = v.size();
    for ( int i = 0; i < v.size(); i++ ) v[i]--;
    vector<int> nv;
    for ( int i = 0; i < v.size(); i++ ) {
      if ( v[i] ) nv.push_back(v[i]);
    }
    v = nv;
    v.push_back(r);
    cnt++;
    if ( cnt > LIM ) return cnt;
  }
}

int main(){
  for ( int i = 0; i <= SMAX; i++ ) valid[i] = false;
  int cur = 3, d = 3;
  while( cur <= SMAX ){
    valid[cur] = true;
    cur += d;
    d++;
  }

  int n;
  int tcase = 0;
  while(1){
    cin >> n;
    if ( n == 0 ) break;
    tcase++;
    assert( NMIN <= n && n <= NMAX);
    vector<int> v;
    int x;
    int sum = 0;
    for ( int i = 0; i < n ;i++) {
      cin >> x;
      assert( BMIN <= x && x <= BMAX);
      v.push_back(x);
      sum += x;
    }
    int ans = simulate(v, sum);
    if ( ans > 10000 ) cout << -1 << endl;
    else cout << ans << endl;
  }
  assert( tcase <= TCASE );
}