6 3 5 9 12 15 17 6 3 5 9 12 30 40
3 -1
//
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=101000;
int n;
int a[maxn];
int f[maxn][12];//dp[i][j]表示i位置,i+j位置的两个人
int main()
{
while(scanf("%d",&n)==1&&n)
{
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
memset(f,-1,sizeof(f));
f[1][1]=0;
for(int i=2;i<=n;i++)
{
for(int j=1;i+j<=n&&a[i+j]-a[i]<=10;j++)
{
for(int k=1;i-k>=1&&a[i+j]-a[i-k]<=10;k++)
{
if(f[i-k][k]==-1) continue;
if(f[i][j]==-1) f[i][j]=f[i-k][k]+1;
else f[i][j]=min(f[i][j],f[i-k][k]+1);
}
}
}
int ans=-1;
for(int i=n-1;i>=1&&a[n]-a[i]<=10;i--)
{
if(f[i][n-i]==-1) continue;
if(ans==-1) ans=f[i][n-i];
else ans=min(ans,f[i][n-i]);
}
printf("%d\n",ans);
}
return 0;
}