#include<cstdio>
using namespace std;
#define N 210
#define QLEN 205
int n,S,T,d[N];
bool vis[N];
struct node{
int p,step;
}que[N];
void bfs(){
int h=0,t=1;
que[1].p=S;
que[1].step=0;
if(que[t].p==T){
printf("%d\n",que[t].step);
return ;
}
while(h!=t){
if(++h>QLEN) h=1;
node up=que[h];
int px=up.p+d[up.p];
if(!vis[px]&&px<=n){
vis[px]=1;
if(++t>QLEN) t=1;
que[t].p=px;
que[t].step=que[h].step+1;
if(que[t].p==T){
printf("%d\n",que[t].step);
return ;
}
}
int po=up.p-d[up.p];
if(!vis[po]&&po>=1){
vis[po]=1;
if(++t>QLEN) t=1;
que[t].p=po;
que[t].step=que[h].step+1;
if(que[t].p==T){
printf("%d\n",que[t].step);
return ;
}
}
}
puts("-1");
}
int main(){
scanf("%d%d%d",&n,&S,&T);
for(int i=1;i<=n;i++) scanf("%d",&d[i]);
bfs();
return 0;
}
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
#define N 210
#define QLEN 205
int n,S,T,g[N][N];
int main(){
memset(g,127/3,sizeof g);
scanf("%d%d%d",&n,&S,&T);
if(S==T){puts("0");return 0;}
for(int i=1;i<=n;i++) g[i][i]=1;
for(int i=1,x;i<=n;i++){
scanf("%d",&x);
if(i-x>=1) g[i][i-x]=1;
if(i+x<=n) g[i][i+x]=1;
}
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
}
}
}
printf("%d\n",g[S][T]!=g[0][0]?g[S][T]:-1);
return 0;
}