# p1135 奇怪的电梯
解法一:深度优先搜索(DFS)
#include <bits/stdc++.h>
using namespace std;
int n,a,b,f[2005],ans=1e9;
bool vis[2005];
void dfs(int L,int count)
{
if(count >= ans) return;
if(L == b)
{
ans = min(ans,count);
return;
}
if(f[L] == 0)
return;
if(L+f[L]<=n&&vis[L+f[L]]==false)
{
vis[L + f[L]] = true;
dfs(L+f[L],count+1);
vis[L + f[L]] = false;
}
if(L-f[L]>=1&&vis[L-f[L]]==false)
{
vis[L - f[L]] = true;
dfs(L-f[L],count+1);
vis[L - f[L]] = false;
}
return;
}
signed main()
{
cin>>n>>a>>b;
for(int i = 1; i <= n; i++)
cin>>f[i];
vis[a] = true;
dfs(a,0);
if(ans == 1e9) cout<<-1;
else cout << ans;
return 0;
}