/*
终于AC了,很简单的bfs,我居然卡了那么久,结果居然是我题目的意思看错了,
there is a number Ki(0 <= Ki <= N) on every floor 这句话没有认真读,
我以为是up down 是按题目给我们的顺序按的,结果第一次超内存,后来用hash标记,wrong。。。
后来终于看见那句要命的话了。读懂题目方能开始做题目,切记!!
*/
#include<iostream>//2393959 2010-04-28 14:19:46 Accepted 1548 15MS 296K 1032 B C++ 悔惜晟
#include<queue>
#include<cstring>
using namespace std;
int a, b, n;
bool flag;
int num[205];
bool hash[205];
int dir[2] = {1, -1};
struct node
{
int i;
int t;
};
int bfs( int si, int t )
{
queue<node>q;
node N, P;
N.i = si; N.t = 0;
q.push(N);
hash[N.i] = true;
int j;
while(!q.empty())
{
N = q.front();
if(N.i == b)
{
flag = true;
cout<<N.t<<endl;
break;
}
if(N.t == n)
{
break;
}
q.pop();
for(j = 0; j < 2; j++)
{
P.i = N.i + num[N.i] * dir[j];
if(P.i == b)
{
flag = true;
cout<<N.t + 1<<endl;
return 1;
}
if(hash[P.i])
continue;
if(P.i >= 1 && P.i <= n)
{
hash[P.i] = true;
P.t = N.t + 1;
q.push(P);
}
}
}
return 1;
}
int main()
{
int i;
while(cin>>n && n)
{
cin>>a>>b;
for(i = 1; i <= n; i++)
cin>>num[i];
flag = false;
memset(hash, false, sizeof(hash));
bfs(a, 0);
if(!flag)
cout<<"-1"<<endl;
}
}