/*
終於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;
}
}