#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
	int n;
	int d[1500];
	int e[1500];
	
	while (scanf("%d", &n) && n){
		
		memset(d, -1, sizeof(d));
		for (int i = 0; i < n; i++){
			scanf("%d", &d[i]);
		}
		
		int ct = 0;
		while (ct <= 10000){
			bool flag = true;
			for (int i = 0; i < 1500; i++){
				if (~d[i] && d[i] != i + 1){
					flag = false;
					break;
				}
			}
			
			if (flag == true){
				printf("%d\n", ct);
				goto end;
			}
			
			int nxt = 0;
			for (int i = 0; i < 1500; i++){
				if (~d[i]){
					d[i]--;
					nxt++;
				}
			}
			
			int idx = 0;
			int ok = 1;
			memset(e, -1, sizeof(e));
			for (int i = 0; i < 1500; i++){
				if (d[i] > 0){
					e[idx++] = d[i];
					ok = 1;
				}
				else if (d[i] == 0){
					ok = 0;
				}
			}
			e[idx] = nxt;
			
			for (int i = 0; i < 1500; i++){
				d[i] = e[i];
			}
			ct++;
		}
		
		printf("-1\n");
		end:;
	}
	
	return (0);
}