#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define sq(a) (a)*(a);
#define debug(x) std::cerr<<#x<<"="<<x<<'\n'
#define endl '\n'
#define all(c) (c).begin(),(c).end()
const long long M = (1e9) + 7;
const int N=1e5+1;
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair<int, int> pi;
#define cin std::cin
#define cout std::cout
#define vector std::vector
#define pb push_back
#define pv(x) for(auto y:x)    cout<<y<<" ";    cout<<'\n';
#define fr first
#define sc second
#define ppb pop_back
int main()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,s,t,p;
	cin>>n>>s>>t;
	map<int,int> m;
	static int ans;
	if (s==t) {cout<<ans<<endl;return 0;}
	else ans++;
	rep(i,0,n)
	{
		int temp;
		cin>>temp;
		if(s==i+1) {p=temp;}  //p

		m[i+1]=temp;
	}
	if(p==t) {cout<<ans<<endl;return 0;}
	{
		bool OK=0;
		rep(i,0,n)
		{

			//debug(p);
			p=m[p];
			ans++;
			if(p==t){OK=1; break;	}
		}
		//debug(p);
		if(OK)
		cout<<ans<<endl;
		else
		cout<<-1<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define sq(a) (a)*(a);
#define debug(x) std::cerr<<#x<<"="<<x<<'\n'
#define endl '\n'
#define all(c) (c).begin(),(c).end()
const long long M = (1e9) + 7;
const int N=1e5+1;
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair<int, int> pi;
#define cin std::cin
#define cout std::cout
#define vector std::vector
#define pb push_back
#define pv(x) for(auto y:x)    cout<<y<<" ";    cout<<'\n';
#define fr first
#define sc second
#define ppb pop_back
int main()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,s,t,p;
	cin>>n>>s>>t;
	map<int,int> m;
	static int ans;
	if (s==t) {cout<<ans<<endl;return 0;}
	else ans++;
	rep(i,0,n)
	{
		int temp;
		cin>>temp;
		if(s==i+1) {p=temp;}  //p

		m[i+1]=temp;
	}
	{
		bool OK=0;
		rep(i,0,n)
		{

			//debug(p);
			p=m[p];
			ans++;
			if(p==t){OK=1; break;	}
		}
		//debug(p);
		if(OK)
		cout<<ans<<endl;
		else
		cout<<-1<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define sq(a) (a)*(a);
#define debug(x) std::cerr<<#x<<"="<<x<<'\n'
#define endl '\n'
#define all(c) (c).begin(),(c).end()
const long long M = (1e9) + 7;
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair<int, int> pi;
#define cin std::cin
#define cout std::cout
#define vector std::vector
#define pb push_back
#define pv(x) for(auto y:x)    cout<<y<<" ";    cout<<'\n';
#define fr first
#define sc second
#define ppb pop_back
int main()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,s,t;
	static int ans;
	bool OK=0;
	cin>>n>>s>>t;
	vector <int> v(n),a(n),b(n),l;
	for(auto &x:v) cin>>x;
	rep(i,0,n) a[v[i]-1]=i+1;
	//pv(a);
	if(a[t-1]==s) {cout<<0<<endl;return 0;}
	ans++;
	rep(i,0,n) b[v[i]-1]=a[i];
	l=b;
	//pv(b);
	if(b[t-1]==s) cout<<ans<<endl;
	ans++;
	while(a!=b)
	{
	rep(i,0,n) b[v[i]-1]=l[i];
	//pv(b);
	l=b;
	ans++;
	if(b[t-1]==s) {OK=1;break;}

	}
	if(OK)
	cout<<ans<<endl;
	else
	cout<<-1<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define sq(a) (a)*(a);
#define debug(x) std::cerr<<#x<<"="<<x<<'\n'
#define endl '\n'
#define all(c) (c).begin(),(c).end()
const long long M = (1e9) + 7;
const int N=1e5+1;
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair<int, int> pi;
#define cin std::cin
#define cout std::cout
#define vector std::vector
#define pb push_back
#define pv(x) for(auto y:x)    cout<<y<<" ";    cout<<'\n';
#define fr first
#define sc second
#define ppb pop_back
int main()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,s,t,p;
	cin>>n>>s>>t;
	map<int,int> m;
	static int ans;
	if (s==t) {cout<<ans<<endl;return 0;}
	else ans++;
	rep(i,0,n)
	{
		int temp;
		cin>>temp;
		if(s==i+1) {p=temp;}  //p

		m[i+1]=temp;
	}
	//if(p==t) {cout<<ans<<endl;return 0;}
	{
		bool OK=0;
		rep(i,0,n)
		{

			debug(p);
			p=m[p];
			ans++;
			if(p==t){OK=1; break;	}
		}
		debug(p);
		if(OK)
		cout<<ans%n<<endl;
		else
		cout<<-1<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define pb         push_back
#define all(a)     a.begin(),a.end()
#define ll        long long
#define sz(a)           a.size()

typedef vector<long long>            vi;
vi v ;
int main (){
                int n ,s,t;
                bool ok=false;
                int a = -1;
                cin>>n>>s>>t;
                for(int i =1 ; i<=n ;i++){
                               cin>>v[i];
                }
                if (s==t){cout<<-1 ; return 0;}
              for(int i =1; i<=n ; i++){
                              if(i != 1 && v[s]>v[s+1]){ swap(v[s],v[s+1]); a++;}
                              if(v[s]==v[t]) ok=true;
                              if(ok) break;

              }
             (ok)? cout<<a+1 : cout<<a;
             return 0 ;

}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,m) for(int i=0;i<(int)(m);i++)
#define pb         push_back
#define all(a)     a.begin(),a.end()
#define ll        long long
#define sz(a)           a.size()

typedef vector<long long>            vi;
int s, t,n, v[100009];
int main(){
  scanf("%d%d%d", &n, &s, &t);
    s--;
    t--;
    rep(i,n) {scanf("%d", &v[i]); v[i]--;}
    int x = s,ans = 0;
    while (x != t) {
        ans++;
        x = v[x];
        if (x == s) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}


 #include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define pb         push_back
#define all(a)     a.begin(),a.end()
#define ll        long long
#define sz(a)           a.size()

typedef vector<long long>            vi;
vi v ;
int main(){
  int n ,s,t;
  scanf("%d%d%d", &n, &s, &t);
    s--;
    t--;
    lp(i,n) {scanf("%d", &v[i]); v[i]--;}
    int x = s,ans = 0;
    while (x != t) {
        ans++;
        x = v[x];
        if (x == s) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}


 #include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define pb         push_back
#define all(a)     a.begin(),a.end()
#define ll        long long
#define sz(a)           a.size()

typedef vector<long long>            vi;
vi v ;
int main(){
  int n ,s,t;
  scanf("%d%d%d", &n, &s, &t);
    s--;
    t--;
    lp(i,n) {scanf("%d", &v[i]); v[i]--;}
    int x = s,ans = 0;
    while (x != t) {
        ans++;
        x = p[x];
        if (x == s) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define pb         push_back
#define all(a)     a.begin(),a.end()
#define ll        long long
#define sz(a)           a.size()

typedef vector<long long>            vi;
vi v ;
int main (){
                int n ,s,t;
                cin>>n>>s>>t;
                s--;
                t--;
                 lp(i,n) {cin>>v[i]; v[i]--; }
                 int x = s ;
                 int a = 0 ;
                 if (s==t){cout<<"0" ; return 0;}
                 while (x!= t){
                                 a++;
                                 x=v[x];
                 }
                 return 0 ;
}


#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define pb         push_back
#define all(a)     a.begin(),a.end()
#define ll        long long
#define sz(a)           a.size()

typedef vector<long long>            vi;
vi v ;
int main (){
                int n ,s,t;
                cin>>n>>s>>t;
                s--;
                t--;
                 lp(i,n) {cin>>v[i]; v[i]--; }
                 int x = s ;
                 int a = 0 ;
                 if (s==t){cout<<"0" ; return 0;}
                 while (x!= t){
                                 a++;
                                 x=v[x];
                 }
                 cout<<a;
                 return 0 ;
}


#include <iostream>
#include<string.h>
#include <math.h>
#include<iomanip>
using namespace std;

int main()
{
    long int n,s,t,i,cnt=0;
    cin>>n>>s>>t;
    long int p[n];
    for(i=0;i<n;i++)
    {cin>>p[i];
        p[i]--;}
    t--;s--;

    for(i=0;i<n;i++)
    {
        if((i==p[p[i]]&& (t!=i))||(i==p[i]&&s!=i))
        {
            cout<<-1;
            exit(0);
        }
    }

    while(s!=t)
    {
        s=p[s];
        cnt++;

    }
    cout<<cnt;

}


#include <iostream>
#include<string.h>
#include <math.h>
#include<iomanip>
using namespace std;

int main()
{
    long int n,s,t,i,cnt=0;
    cin>>n>>s>>t;
    long int p[n];
    for(i=0;i<n;i++)
    {cin>>p[i];
        p[i]--;}
    t--;s--;

    while(s!=t)
    {
        s=p[s];
        cnt++;
        if(cnt>10000)
        {
            for(i=0;i<n;i++)
            {
                if((i==p[p[i]]&& (t!=i))||(i==p[i]&&s!=i))
                {
                    cout<<-1;
                    exit(0);
                }
            }
        }

    }
    cout<<cnt;

}


#include <iostream>
#include<string.h>
#include <math.h>
#include<iomanip>
using namespace std;

int main()
{
    long int n,s,s2,t,i,cnt=0;
    cin>>n>>s>>t;
    long int p[n];
    for(i=0;i<n;i++)
    {cin>>p[i];
        p[i]--;}
    t--;s--;
    s2=s;
    if(s==t)
    {cout<<0;exit(0);}

    while(s!=t && s!=s2)
    {
        s=p[s];
        cnt++;

        }
    if(s==s2)
        cout<<-1;
else
    cout<<cnt;

}


#include <iostream>
#include<string.h>
#include <math.h>
#include<iomanip>
using namespace std;

int main()
{
    long int n,s,s2,t,i,cnt=0;
    cin>>n>>s>>t;
    long int p[n];
    for(i=0;i<n;i++)
    {cin>>p[i];
        p[i]--;}
    t--;s--;
    s2=s;
    if(s==t)
    {cout<<0;exit(0);}

    while(s!=t)
    {
        s=p[s];
        cnt++;
        if(s==s2)
        {cout<<-1;
            exit(0);
        }

        }

    cout<<cnt;

}


#include <iostream>
#include<string.h>
#include <math.h>
#include<iomanip>
using namespace std;

int main()
{
    long int n,s,t,i,cnt=0;
    cin>>n>>s>>t;
    long int p[n];
    for(i=0;i<n;i++)
    {cin>>p[i];
        p[i]--;}
    t--;s--;

    while(s!=t)
    {
        s=p[s];
        cnt++;
        if(cnt>100000)
        {
            for(i=0;i<n;i++)
            {
                if((i==p[p[i]]&& (t!=i))||(i==p[i]&&s!=i))
                {
                    cout<<-1;
                    exit(0);
                }
            }
        }

    }
    cout<<cnt;

}


#include<bits/stdc++.h>
using namespace std;
vector<int> v,visit;
int f=0;
int cnt=0;
void dfs(int u,int t)
{
  visit[u]=1;

	if(v[u]==t)
	{
		if(u!=t)
			cnt++;
		f=1;
		return ;
	}
	else if(!visit[v[u]])
	{
		cnt++;
		dfs(v[u],t);
	}
	else
		return ;

}
int main()
{
	int n,s,t;
	cin>>n>>s>>t;
	v.resize(n+1);
	visit.resize(n+1,0);
	int x;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		v[i]=x;
	}
	dfs(s,t);
   if(f)
   	cout<<cnt<<endl;
   else
   	cout<<-1<<endl;

}


#include<bits/stdc++.h>
using namespace std;
vector<int> v,visit;
int f=0;
int cnt=0;
void dfs(int u,int t)
{
  visit[u]=1;

	if(v[u]==t)
	{
		f=1;
		return ;
	}
	else if(!visit[v[u]])
	{
		cnt++;
		dfs(v[u],t);
	}
	else
		return ;

}
int main()
{
	int n,s,t;
	cin>>n>>s>>t;
	v.resize(n+1);
	visit.resize(n+1,0);
	int x;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		v[i]=x;
	}
	if(t==s)
	{
		f=1;
	}
	else
	dfs(s,t);
   if(f)
   	cout<<cnt<<endl;
   else
   	cout<<-1<<endl;

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n,s,t;
	cin>>n>>s>>t;
	int a[n+1],x,b[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		b[i]=x;
		a[x]=i;
	}

	if(b[t]!=s)
	{
		cout<<-1<<"\n";
		return 0;
	}
	if(t==s)
	{
		cout<<0<<"\n";
		return 0;
	}
    int c=0;
    int i=t;
    while(c<n)
    {
    	c++;
    	//cout<<a[i]<<" ";
       if(a[i]==s)
       	break;
       i=a[i];

    }
    //cout<<"\n";
    if(c==n)
    {
    	cout<<-1<<"\n";
    	return 0;
    }
    else
    	cout<<c<<"\n";

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n,s,t;
	cin>>n>>s>>t;
	int a[n+1],x,b[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		b[i]=x;
		a[x]=i;
	}

	if(b[t]!=s)
	{
		cout<<-1<<"\n";
		return 0;
	}
	if(t==s)
	{
		cout<<0<<"\n";
		return 0;
	}
    int c=0;
    int i=t;
    while(c<n)
    {

    	//cout<<a[i]<<" ";
       if(a[i]==t)
       	break;
       i=a[i];
        c++;

    }
    //cout<<"\n";
    if(c==n)
    {
    	cout<<-1<<"\n";
    	return 0;
    }
    else
    	cout<<c<<"\n";

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n,s,t;
	cin>>n>>s>>t;
	int a[n+1],x,b[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		b[i]=x;
		a[x]=i;
	}

	if(b[t]!=s)
	{
		cout<<-1<<"\n";
		return 0;
	}
	if(t==s)
	{
		cout<<0<<"\n";
		return 0;
	}
    int c=0;
    int i=s;
    while(c<n)
    {

    	//cout<<a[i]<<" ";
       if(a[i]==s)
       	break;
       i=a[i];
      c++;
    }
    //cout<<"\n";
    if(c==n)
    {
    	cout<<-1<<"\n";
    	return 0;
    }
    else
    	cout<<c<<"\n";

}


#include<bits/stdc++.h>
using namespace std;
vector<int> v,visit;
int f=0;
int cnt=0;
void dfs(int u,int t)
{
  visit[u]=1;

	if(v[u]==t)
	{
		cnt++;
		f=1;
		return ;
	}
	else if(!visit[v[u]])
	{
		cnt++;
		dfs(v[u],t);
	}
	else
		return ;

}
int main()
{
	int n,s,t;
	cin>>n>>s>>t;
	v.resize(n+1);
	visit.resize(n+1,0);
	int x;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		v[i]=x;
	}
	if(t==s)
	{
		f=1;
	}
	else
	dfs(s,t);
   if(f)
   	cout<<cnt<<endl;
   else
   	cout<<-1<<endl;

}


#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;
int main(){
    long long int n,p1,p2;
    cin>>n>>p1>>p2;
    long long int t=0,a;
    long long int temp[n];//3 1 3
    bool found=false;
    for (int i=0;i<n;i++){//2 1 3
        cin>>a;
        temp[i]=a;
    }
    while(p1!=p2){
        if (p2==temp[p2-1]){
            found=true;
            break;
        }
        p1=temp[p1-1];
        t++;
    }
    if (found==false){
        cout<<t;
    }else{
        cout<<-1;
    }
}


#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;
int main(){
    long long int n,p1,p2;
    cin>>n>>p1>>p2;
    long long int t=0,a;
    long long int temp[n];//3 1 3
    bool found=false;
    for (int i=0;i<n;i++){//2 1 3
        cin>>a;
        temp[i]=a;
    }
    while(p1!=p2){
        if (p2==temp[p2-1] || p1==temp[p1-1]){
            found=true;
            break;
        }
        p1=temp[p1-1];
        t++;
    }
    if (found==false){
        cout<<t;
    }else{
        cout<<-1;
    }
}


#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;
int main(){
    long long int n,p1,p2;
    cin>>n>>p1>>p2;
    long long int t=0,a;
    long long int temp[n];
    bool found=false;
    for (int i=0;i<n;i++){
        cin>>a;
        temp[i]=a;
    }
    while(p1!=p2){
        if (p1!=temp[p1-1]){
            p1=temp[p1-1];
        }else{
            found=true;
            break;
        }
        t++;
    }
    if (found==false){
        cout<<t;
    }else{
        cout<<-1;
    }
}


#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;
int main(){
    long long int n,p1,p2;
    cin>>n>>p1>>p2;
    long long int t=0,a;
    long long int temp[n];//3 1 3
    bool found=false;
    for (int i=0;i<n;i++){//2 1 3
        cin>>a;
        temp[i]=a;
    }
    unordered_map<int,int> all;
    while(p1!=p2){
        p1=temp[p1-1];
        if (all[p1]!=0){
            found=true;
            break;
        }
        all[p1]++;
        t++;
    }
    if (found==false){
        cout<<t;
    }else{
        cout<<-1;
    }
}


#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;
int main(){
    long long int n,p1,p2;
    cin>>n>>p1>>p2;
    long long int t=0;
    long long int temp;
    bool found=false;
    for (int i=0;i<n;i++){
        cin>>temp;
        if (i+1==p1){
            p1=temp;
            if (p1!=p2){
                found=true;
            }
        }
        if (found==true){
            t++;
        }
    }
    if (p1==p2){
        cout<<t;
    }else{
        cout<<-1;
    }
}


#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;
int main(){
    long long int n,p1,p2;
    cin>>n>>p1>>p2;
    long long int t=0,a;
    long long int temp[n];//3 1 3
    bool found=false;
    for (int i=0;i<n;i++){//2 1 3
        cin>>a;
        temp[i]=a;
    }
    while(p1!=p2){
        a=p1;
        p1=temp[p1-1];
        t++;
        if (p2==temp[p2-1] || p1==temp[p1-1] || p1==temp[a-1] && a==temp[p1-1]){
            found=true;
            break;
        }
    }
    if (found==false){
        cout<<t;
    }else{
        cout<<-1;
    }
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#include<iomanip>
using namespace std;
int main()
{
	int n,x,y, s, t, a[100000]; cin >> n >> s >> t;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] == s)
			x = i;
		if (a[i] == t)
			 y = i;
	}
	if (abs(y - x) == 1||x>y)
		cout << -1 << endl;
	else
		cout << abs(y - x) << endl;
	//system("pause");
}


#define _CRT_SECURE_NO_WARNINGS
//           Allah_Almost3aan
//*{ربى.. كنْ لىِ خيرَ مدبر فإنى لا احسنُ التدبير}*
#include<bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long int lli;
typedef  long long ll;
typedef  unsigned long long ull;
typedef  long double ld;
#define ed "\n"
#define INF 1e9
#define SZ 1000007
#define ff first
#define ss second
#define sz(a) a.size()
#define RT(v) return cout<<v<<ed,0
#define stpr(n) fixed<<setprecision(n)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
string ys = "YES", no = "NO", st;
int di[8] = { 1, 0, -1, 0, -1, 1, -1, 1 };
int dj[8] = { 0, -1, 0, 1, 1, 1, -1, -1 };
const int N = 1.5 * 10000000 + 16;
const lli  OO = 1e18;
lli mod = 1e9 + 7;
void fast() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
}
int main()
{
	fast();
	int q;	//cin >> q;
	q = 1;
	while (q--)
	{
		int n, s, f,cnt=0;
		cin >> n >> s >> f;
		if (s == f) RT(0);
		vector<int>v(n + 1);
		for (int i = 1; i <= n; i++) cin >> v[i];
		int i = 1;
		map<int, int>mp;
		while (true)
		{
			i = v[i];
			if (mp[i]>1)RT(-1);
			if (i == f)
				RT(cnt);
			cnt++;
			if (i == v[i] && i != f) RT(-1);
			//if (v[v[i]] == i&&i != f) RT(-1);
			mp[i]++;
		}
	}
}


#define _CRT_SECURE_NO_WARNINGS
//           Allah_Almost3aan
//*{ربى.. كنْ لىِ خيرَ مدبر فإنى لا احسنُ التدبير}*
#include<bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long int lli;
typedef  long long ll;
typedef  unsigned long long ull;
typedef  long double ld;
#define ed "\n"
#define INF 1e9
#define SZ 1000007
#define ff first
#define ss second
#define sz(a) a.size()
#define RT(v) return cout<<v<<ed,0
#define stpr(n) fixed<<setprecision(n)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
string ys = "YES", no = "NO", st;
int di[8] = { 1, 0, -1, 0, -1, 1, -1, 1 };
int dj[8] = { 0, -1, 0, 1, 1, 1, -1, -1 };
const int N = 1.5 * 10000000 + 16;
const lli  OO = 1e18;
lli mod = 1e9 + 7;
void fast() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
}
int main()
{
	fast();
	int q;	//cin >> q;
	q = 1;
	while (q--)
	{
		int n, s, f,cnt=0;
		cin >> n >> s >> f;
		if (s == f) RT(0);
		vector<int>v(n + 1);
		for (int i = 1; i <= n; i++) cin >> v[i];
		map<int, int>mp;
		while (s!=f)
		{
			if (mp[s])RT(-1);
			cnt++;
			mp[s]++;
			s = v[s];
		}
		RT(cnt);
	}
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#include<iomanip>
using namespace std;
int main()
{
	int n,x,y, s, t, a[100000]; cin >> n >> s >> t;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] == s)
			x = i;
		if (a[i] == t)
			 y = i;
	}
	if (abs(y - x) == 1)
		cout << -1 << endl;
	else
		cout << abs(y - x) << endl;
	//system("pause");
}


#define _CRT_SECURE_NO_WARNINGS
//           Allah_Almost3aan
//*{ربى.. كنْ لىِ خيرَ مدبر فإنى لا احسنُ التدبير}*
#include<bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long int lli;
typedef  long long ll;
typedef  unsigned long long ull;
typedef  long double ld;
#define ed "\n"
#define INF 1e9
#define SZ 1000007
#define ff first
#define ss second
#define sz(a) a.size()
#define RT(v) return cout<<v<<ed,0
#define stpr(n) fixed<<setprecision(n)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
string ys = "YES", no = "NO", st;
int di[8] = { 1, 0, -1, 0, -1, 1, -1, 1 };
int dj[8] = { 0, -1, 0, 1, 1, 1, -1, -1 };
const int N = 1.5 * 10000000 + 16;
const lli  OO = 1e18;
lli mod = 1e9 + 7;
void fast() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
}
int main()
{
	fast();
	int q;	//cin >> q;
	q = 1;
	while (q--)
	{
		int n, s, f,cnt=0;
		cin >> n >> s >> f;
		if (s == f) RT(0);
		vector<int>v(n + 1);
		for (int i = 1; i <= n; i++) cin >> v[i];
		int i = 1;
		while (true)
		{
			i = v[i];
			if (i == f)
				RT(cnt);
			cnt++;
			if (i == v[i] && i != f) RT(-1);
			if (v[v[i]] == i&&i != f) RT(-1);
		}
	}
}


#define _CRT_SECURE_NO_WARNINGS
//           Allah_Almost3aan
//*{ربى.. كنْ لىِ خيرَ مدبر فإنى لا احسنُ التدبير}*
#include<bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long int lli;
typedef  long long ll;
typedef  unsigned long long ull;
typedef  long double ld;
#define ed "\n"
#define INF 1e9
#define SZ 1000007
#define ff first
#define ss second
#define sz(a) a.size()
#define RT(v) return cout<<v<<ed,0
#define stpr(n) fixed<<setprecision(n)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
string ys = "YES", no = "NO", st;
int di[8] = { 1, 0, -1, 0, -1, 1, -1, 1 };
int dj[8] = { 0, -1, 0, 1, 1, 1, -1, -1 };
const int N = 1.5 * 10000000 + 16;
const lli  OO = 1e18;
lli mod = 1e9 + 7;
void fast() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
}
int main()
{
	fast();
	int q;	//cin >> q;
	q = 1;
	while (q--)
	{
		int n, s, f,cnt=0;
		cin >> n >> s >> f;
		if (s == f) RT(0);
		vector<int>v(n + 1);
		for (int i = 1; i <= n; i++) cin >> v[i];
		int i = 1;
		map<int, int>mp;
		while (true)
		{
			i = v[i];
			if (mp[i])RT(-1);
			if (i == f)
				RT(cnt);
			cnt++;
			if (i == v[i] && i != f) RT(-1);
			if (v[v[i]] == i&&i != f) RT(-1);
			mp[i]++;
		}
	}
}


#include <bits/stdc++.h>
using namespace std;

int main() {

	map<int,int> m;
	int n,s,t;
	cin>>n>>s>>t;
	int x;
	int i=1;
	int temp=n;
	while(temp--)
	{
		cin>>x;
		m[i]=x;
		i++;
	}

	if(s==t)
	{
		cout<<0;
		return 0;
	}
	int cnt=0;
	while(1)
	{

		if(m[s]==t)
		{

			cout<<cnt+1;
			return 0;
		}
		s=m[s];
		cnt++;
		if(cnt>n+1)
		{

			cout<<-1;
			break;
		}
	}
	// your code goes here
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {

	map<int,int> m;
	int n,s,t;
	cin>>n>>s>>t;
	int x;
	int i=1;
	while(n--)
	{
		cin>>x;
		m[i]=x;
		i++;
	}
	int cnt=0;
	while(1)
	{

		if(m[s]==t && cnt==0)
		{
			cout<<0;
			return 0;
		}
		else if(m[s]==t)
		{
			cout<<cnt+1;
			return 0;
		}
		s=m[s];
		cnt++;
		if(cnt>n)
		{
			cout<<-1;
			break;
		}
	}
	// your code goes here
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {

	map<int,int> m;
	int n,s,t;
	cin>>n>>s>>t;
	int x;
	int i=1;
	while(n--)
	{
		cin>>x;
		m[i]=x;
		i++;
	}
	int cnt=0;
	while(1)
	{

		if(m[s]==t)
		{
			if(cnt==0)
			{
				cout<<0;
				return 0;
			}
			cout<<cnt+1;
			return 0;
		}
		s=m[s];
		cnt++;
		if(cnt>n)
		{
			cout<<-1;
			break;
		}
	}
	// your code goes here
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {

	map<int,int> m;
	int n,s,t;
	cin>>n>>s>>t;
	int x;
	int i=1;
	while(n--)
	{
		cin>>x;
		m[i]=x;
		i++;
	}
	int cnt=0;
	while(1)
	{

		if(m[s]==t)
		{
			if(cnt==0)
			{
				cout<<0;
				return 0;
			}
			cout<<cnt+1;
			return 0;
		}
		s=m[s];
		cnt++;
		if(cnt==n)
		{
			cout<<-1;
			break;
		}
	}
	// your code goes here
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {

	map<int,int> m;
	int n,s,t;
	cin>>n>>s>>t;
	int x;
	int i=1;
	int temp=n;
	while(temp--)
	{
		cin>>x;
		m[i]=x;
		i++;
	}
	int cnt=0;
	while(1)
	{

		if(m[s]==t)
		{
			if(cnt==0)
			{
				cout<<0;
				return 0;
			}
			cout<<cnt+1;
			return 0;
		}
		s=m[s];
		cnt++;
		if(cnt>n+1)
		{

			cout<<-1;
			break;
		}
	}
	// your code goes here
	return 0;
}


#include <bits/stdc++.h>
#include<string.h>
#include<math.h>
#define ll long long
#define M 1000000007
using namespace std;

int main()
{
    int n,s,t;
    cin>>n>>s>>t;
    int a[n]={};
    int i,p[n],si,ti;
    for(i=0;i<n;i++)
    {
        cin>>p[i];
        if(p[i]==i+1)
            a[i]=-1;
    }
    if(s==t)
        cout<<0<<endl;
    else if(a[s-1]==(-1) || a[t-1]==(-1))
    {
        cout<<-1<<endl;
    }
    else
    {
        int k=s,cnt=0;
        while(a[t-1]!=s)
        {
            k=p[k-1];
            a[k-1]=s;
            cnt++;
        }
        cout<<cnt<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include<string.h>
#include<math.h>
#define ll long long
#define M 1000000007
using namespace std;

int main()
{
    int n,s,t;
    cin>>n>>s>>t;
    int i,p[n],si,ti;
    for(i=0;i<n;i++)
    {
        cin>>p[i];
        if(p[i]==s)
            si=i;
        else if(p[i]==t)
            ti=i;
    }
    if(s==t)
        cout<<0<<endl;
    else
    {
        if(s==p[0])
        {
            cout<<ti<<endl;
        }
        else
        {
            if(ti<si)
            {
                cout<<ti+1<<endl;
            }
            else
            {
                cout<<-1<<endl;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#include<string.h>
#include<math.h>
#define ll long long
#define M 1000000007
using namespace std;

int main()
{
    int n,s,t;
    cin>>n>>s>>t;
    int i,p[n],si,ti;
    for(i=0;i<n;i++)
    {
        cin>>p[i];
        if(p[i]==s)
            si=i;
        else if(p[i]==t)
            ti=i;
    }
    if(s==t)
        cout<<0<<endl;
    else
    {
        if(s==p[0])
            cout<<ti<<endl;
        else
            cout<<-1<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include<string.h>
#include<math.h>
#define ll long long
#define M 1000000007
using namespace std;

int main()
{
    int n,s,t;
    cin>>n>>s>>t;
    int i,p[n],si,ti;
    for(i=0;i<n;i++)
    {
        cin>>p[i];
    }
    if(s==t)
        cout<<0<<endl;
    else
    {
        int k=s,cnt=0;
        while(t!=s && p[s-1]!=(-1))
        {
            k=p[s-1];
            p[s-1]=(-1);
            s=k;
            cnt++;
        }
        if(s==t)
            cout<<cnt<<endl;
        else
            cout<<-1<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n;
	cin>>n;
	int s,t;
	cin>>s>>t;
	int a[n];
	for(int i=0; i<n; i++)cin>>a[i];
	int f=s,d=0;
	while(f!=t && d<=n)
	{
		f=a[s-1];
		s=f;
		d++;
	}

	if(f==t)cout<<d;
	else cout<<"-1";

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n,s,t,qq=0,pp=1,op=0;
    cin>>n>>s>>t;
    int ar[n],br[n],cr[n];
    for(int i=0;i<n;i++)
    cin>>ar[i];
    for(int i=0;i<n;i++)
    br[ar[i]-1]=i+1;
    int u;
    if(br[t-1]==t)op=1;
    for(u=0;u<n;u++)
    if(br[u]==s)break;
    if(s==t) cout<<"0";
    else
    {
    while(pp>0)
      {
      if(op==1)
      {
        cout<<"-1";
        break;
      }
      int l=u-s+1;
      s=s+l;
      qq++;
      s=s%n;
      if(s%t==0)
      {
        cout<<qq;
        break;
      }
      }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n,s,t,qq=0,pp=1,op=0;
    cin>>n>>s>>t;
    int ar[n],br[n],cr[n];
    for(int i=0;i<n;i++)
    cin>>ar[i];
    if(s==t) cout<<"0";
    else
    {
        for(int i=0;i<n;i++)
        {
            cin>>cr[i];
            br[i]=cr[i];
        }
        while(pp>0)
        {
            for(int i=0;i<n;i++)
            br[ar[i]-1]=cr[i];
            for(int i=0;i<n;i++)
            {
                if(br[i]==cr[i])
                {
                  op=1;
                  break;
                }
            }
            for(int i=0;i<n;i++)
            cr[i]=br[i];

            qq++;
            if(br[t-1]==s)break;
        }
        if(op==0)
        cout<<qq;
        else cout<<"-1";
        //br[ar[i]-1]=cr[i];
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n,s,t,qq=0,pp=1,op=0;
    cin>>n>>s>>t;
    int ar[n],br[n],cr[n];
    for(int i=0;i<n;i++)
    cin>>ar[i];
    if(s==t) cout<<"0";
    else
    {
        for(int i=0;i<n;i++)
        {
            cin>>cr[i];
            br[i]=cr[i];
        }
        while(pp>0)
        {
            for(int i=0;i<n;i++)
            br[ar[i]-1]=cr[i];
            for(int i=0;i<n;i++)
            {
                if(br[i]==cr[i])
                {
                  op=1;
                  break;
                }
            }
            if(op==1) break;
            for(int i=0;i<n;i++)
            cr[i]=br[i];

            qq++;
            if(br[t-1]==s)break;
        }
        if(op==0)
        cout<<qq;
        else cout<<"-1";
        //br[ar[i]-1]=cr[i];
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n,s,t,qq=0,pp=1,op=0;
    cin>>n>>s>>t;
    int ar[n],br[n];
    for(int i=0;i<n;i++)
    cin>>ar[i];
    for(int i=0;i<n;i++)
    br[ar[i]-1]=i+1;

    int u;
    if(br[t-1]==t)op=1;

    if(s==t) cout<<"0";
    else
    {
    while(pp>0)
      {
          if(op==1)
          {
              cout<<"-1";
              break;
          }
          else
              { int l=ar[0]-1;

               s=s+l;
               qq++;
               s=s%n;
               if(s==t)
          {
             cout<<qq;
             break;
          }
           else continue;
          }
      }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n,s,t,qq=0,pp=1,op=0;
    cin>>n>>s>>t;
    int ar[n],br[n];
    for(int i=0;i<n;i++)
    cin>>ar[i];
    for(int i=0;i<n;i++)
    br[ar[i]-1]=i+1;

    int u;
    if(br[t-1]==t || br[s-1]==s)op=1;

    if(s==t) cout<<"0";
    else
    {
    while(pp>0)
      {
          if(op==1)
          {
              cout<<"-1";
              break;
          }
          else
              { int l=ar[0]-1;

               s=s+l;
               qq++;
               s=s%n;
               if(s==t)
          {
             cout<<qq;
             break;
          }
           else continue;
          }
      }
    }
}


/*
    ######## ##   ## #######          ##########
       ##    ##   ## ##                 ##    ##
       ##    ####### ######             ##    ##
       ##    ##   ## ##                 ##    ##
       ##    ##   ## ####### ######## ##########
*/
#include<bits/stdc++.h>
#include <iomanip>
#define int         long long
#define ll             long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define maxc(v)     max_element(all(v))
#define minc(v)     min_element(all(v))
#define endl        "\n"
using namespace std;

#define N  100005
int abs(int a, int b){
    if(a>b) return a-b;
    else return b-a;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--)
    {
        ll n,s,t,pos=0,step=0;
        cin>>n>>s>>t;
        int a[n+1];
        a[0]=0;
        pos = s;
        rep(i,1,n+1) cin>>a[i];
        if(a[t]==t&&s-t) {
            step=-1;
            pos=t;
        }
        while(pos-t){
                    if(a[pos]==pos) {
                    step=-1;
                    break;
                }
                pos=a[pos];
                step++;
                if(step>n) {
                    step=-1;
                    break;
                }
            }
        cout<<step<<endl;
    }
    return 0;
}


/*
    ######## ##   ## #######          ##########
       ##    ##   ## ##                 ##    ##
       ##    ####### ######             ##    ##
       ##    ##   ## ##                 ##    ##
       ##    ##   ## ####### ######## ##########
*/
#include<bits/stdc++.h>
#include <iomanip>
#define int         long long
#define ll             long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define maxc(v)     max_element(all(v))
#define minc(v)     min_element(all(v))
#define endl        "\n"
using namespace std;

#define N  100005
int abs(int a, int b){
    if(a>b) return a-b;
    else return b-a;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--)
    {
        ll n,s,t,pos=0,step=0;
        cin>>n>>s>>t;
        int a[n+1];
        a[0]=0;
        pos = s;
        rep(i,1,n+1) cin>>a[i];
        if(a[t]==t) {
            step=-1;
            pos=t;
        }
        while(pos-t){
                    if(a[pos]==pos) {
                    step=-1;
                    break;
                }
                pos=a[pos];
                step++;
            }
        cout<<step<<endl;
    }
    return 0;
}


/*
    ######## ##   ## #######          ##########
       ##    ##   ## ##                 ##    ##
       ##    ####### ######             ##    ##
       ##    ##   ## ##                 ##    ##
       ##    ##   ## ####### ######## ##########
*/
#include<bits/stdc++.h>
#include <iomanip>
#define int         long long
#define ll             long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define maxc(v)     max_element(all(v))
#define minc(v)     min_element(all(v))
#define endl        "\n"
using namespace std;

#define N  100005
int abs(int a, int b){
    if(a>b) return a-b;
    else return b-a;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--)
    {
        int n,s,t;
        cin>>n>>s>>t;
        map<int, int> m;
        int z;
        rep(i,1,n+1) {
            cin>>z;
            m.insert({ i , z });
        }
        z=0; int i = s;
        if(s!=t&&m[t]==t) z=-1;
        else{
        for(;;z++){
            if(i==t) break;
            else if(i==m[i]) {
                z=-1;
                break;
            }
            else{
                i = m[i];
            }
        }}
        cout<<z<<endl;
    }
    return 0;
}


/*
    ######## ##   ## #######          ##########
       ##    ##   ## ##                 ##    ##
       ##    ####### ######             ##    ##
       ##    ##   ## ##                 ##    ##
       ##    ##   ## ####### ######## ##########
*/
#include<bits/stdc++.h>
#include <iomanip>
#define int         long long
#define ll             long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define maxc(v)     max_element(all(v))
#define minc(v)     min_element(all(v))
#define endl        "\n"
using namespace std;

#define N  100005
int abs(int a, int b){
    if(a>b) return a-b;
    else return b-a;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--)
    {
        ll n,s,t,pos=0,step=0;
        cin>>n>>s>>t;
        int a[n+1];
        a[0]=0;
        pos = s;
        rep(i,1,n+1) cin>>a[i];
        if(a[t]==t&&s-t) {
            step=-1;
            pos=t;
        }
        while(pos-t){
                    if(a[pos]==pos) {
                    step=-1;
                    break;
                }
                pos=a[pos];
                step++;
            }
        cout<<step<<endl;
    }
    return 0;
}


/*
    ######## ##   ## #######          ##########
       ##    ##   ## ##                 ##    ##
       ##    ####### ######             ##    ##
       ##    ##   ## ##                 ##    ##
       ##    ##   ## ####### ######## ##########
*/
#include<bits/stdc++.h>
#include <iomanip>
#define int         long long
#define ll             long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define maxc(v)     max_element(all(v))
#define minc(v)     min_element(all(v))
#define endl        "\n"
using namespace std;

#define N  100005
int abs(int a, int b){
    if(a>b) return a-b;
    else return b-a;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--)
    {
        ll n,s,t,pos=0,step=0,i;
        cin>>n>>s>>t;
        int a[n+1];
        a[0]=0;
        pos = s;
        i=n;
        rep(i,1,n+1) cin>>a[i];
        if(a[t]==t&&s-t) {
            step=-1;
            pos=t;
        }
        while(pos-t&&i--){
                    if(a[pos]==pos) {
                    step=-1;
                    break;
                }
                pos=a[pos];
                step++;
            }
        if(i==0) step=-1;
        cout<<step<<endl;
    }
    return 0;
}


/*
    ######## ##   ## #######          ##########
       ##    ##   ## ##                 ##    ##
       ##    ####### ######             ##    ##
       ##    ##   ## ##                 ##    ##
       ##    ##   ## ####### ######## ##########
*/
#include<bits/stdc++.h>
#include <iomanip>
#define int         long long
#define ll             long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define maxc(v)     max_element(all(v))
#define minc(v)     min_element(all(v))
#define endl        "\n"
using namespace std;

#define N  100005
int abs(int a, int b){
    if(a>b) return a-b;
    else return b-a;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--)
    {
        ll n,s,t,pos=0,step=0;
        cin>>n>>s>>t;
        int a[n+1];
        a[0]=0;
        pos = s;
        rep(i,1,n+1) cin>>a[i];
        if(a[t]==t&&s-t) {
            step=-1;
            pos=t;
        }
        while(pos-t){
                    if(a[pos]==pos) {
                    step=-1;
                    break;
                }
                pos=a[pos];
                step++;
                if(step>100) {
                    step=-1;
                    break;
                }
            }
        cout<<step<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int s,t;int e=0;
    cin>>s>>t;
    int ar[n];
    for(int i=0;i<n;i++)
    cin>>ar[i];
    if(s==t)
    cout<<0;
    else
    {
        bool x=true;
        while(x)
        {
            if(ar[s-1]!=s)
            {
                s=ar[s-1];e++;
                if(s==t)
                break;
            }
            else
            x=false;
        }

    if(s==t)
    cout<<e;
    else
    cout<<"-1";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int s,t;int e=0;
    cin>>s>>t;
    int ar[n];int c=s;
    for(int i=0;i<n;i++)
    cin>>ar[i];
    if(s==t)
    cout<<0;
    else
    {
        bool x=true;
        while(x)
        {
            if(ar[s-1]!=s && ar[s-1]!=c)
            {
                s=ar[s-1];e++;
                if(s==t)
                break;
            }
            else
            x=false;
        }

    if(s==t)
    cout<<e;
    else
    cout<<"-1";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int s,t;int e=0;
    cin>>s>>t;
    int ar[n];
    for(int i=0;i<n;i++)
    cin>>ar[i];
    if(s==t)
    cout<<0;
    else
    {
        bool x=true;
        while(x)
        {
            if(ar[s-1]!=s)
            {
                s=ar[s-1];e++;
                if(s==t)
                break;
            }
            else
            x=false;
        }

    }
    if(s==t)
    cout<<e;
    else
    cout<<"-1";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int s,t;int e=0;
    cin>>s>>t;
    int ar[n];
    for(int i=0;i<n;i++)
    cin>>ar[i];
    if(s==t)
    cout<<0;
    else
    {
        bool x=true;
        while(x)
        {
            if(ar[s-1]!=s)
            {
                s=ar[s-1];e++;
                if(s==t)
                break;
            }
            else
            x=false;
        }

    }
    if(s==t)
    cout<<e;
    else<<"-1";
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    long long int n,s,t,a,b,flag=0;
    long long int arr[100000];
    cin>>n>>s>>t;
    for(int i=0;i<n;i++)
    cin>>arr[i];
    if(t>s && (abs(s-t)==1))
      {
         cout<<-1;
         flag=1;
      }
    if(s==t)
    {
      cout<<0;
      flag =1;}
    for(int i=0;i<(n-1);i++)
    {if(arr[i]==s && (arr[i+1]==t ))
       { cout<<-1;
          flag=1;
          break;
       }

    }
    for(int i=0;i<n;i++)
    {
       if(arr[i]==s)
       a=i;
       if(arr[i]==t)
       b=i;
    }
    if(flag==0)
    cout<<abs(a-b);

}


#include<iostream>
using namespace std;
int main()
{
    long long int n,s,t,a,b,flag=0;
    long long int arr[100000];
    cin>>n>>s>>t;
    for(int i=0;i<n;i++)
    cin>>arr[i];
    if(t>s && (abs(s-t)==1))
      {
         cout<<-1;
         flag=1;
      }
    if(s==t)
    {
      cout<<0;
      flag =1;}
    for(int i=0;i<(n-1);i++)
    {if(arr[i]==s && (arr[i+1]==t ) && flag==0)
       { cout<<-1;
          flag=1;
          break;
       }

    }
    for(int i=0;i<n;i++)
    {
       if(arr[i]==s)
       a=i;
       if(arr[i]==t)
       b=i;
    }
    if(flag==0)
    cout<<abs(a-b);

}


#include<iostream>
using namespace std;
int main()
{
    long long int n,s,t,a,b,flag=0;
    long long int arr[100000];
    cin>>n>>s>>t;
    for(int i=0;i<n;i++)
    cin>>arr[i];
    if(s==t)
    {
      cout<<0;
      flag =1;}
    for(int i=0;i<(n-1);i++)
    {if(arr[i]==s && (arr[i+1]==t ))
       { cout<<-1;
          flag=1;
          break;
       }

    }
    for(int i=0;i<n;i++)
    {
       if(arr[i]==s)
       a=i;
       if(arr[i]==t)
       b=i;
    }
    if(flag==0)
    cout<<abs(a-b);

}


#include<iostream>
using namespace std;
int main()
{
    long long int n,s,t,a,b,flag=0;
    long long int arr[100000];
    cin>>n>>s>>t;
    for(int i=0;i<n;i++)
    cin>>arr[i];
    if(abs(s-t)==1)
      {
         cout<<-1;
         flag=1;
      }
    if(s==t)
    {
      cout<<0;
      flag =1;}
    for(int i=0;i<(n-1);i++)
    {if(arr[i]==s && (arr[i+1]==t ))
       { cout<<-1;
          flag=1;
          break;
       }

    }
    for(int i=0;i<n;i++)
    {
       if(arr[i]==s)
       a=i;
       if(arr[i]==t)
       b=i;
    }
    if(flag==0)
    cout<<abs(a-b);

}


#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    int x=0,y=0,l;
    char a[200];
    cin>>a;
    l = strlen(a);
    for(int i=0;i<l;i++)
    {
        if(a[i]=='L')
          x-=1;
        if(a[i] == 'R')
        x +=1;
        if(a[i]=='D')
         y -=1;
        if(a[i]=='U')
         y+=1;
    }
    cout<<x<<" "<<y;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,s,t;
    cin>>n>>s>>t;
    int arr[n];
    for (int i=0;i<n;i++)
    {
        cin>>arr[i];
        arr[i]=arr[i]-1;
    }
    int start,en
    start=s-1;
    end=t-1;
    if (start==end)
        cout<<"0"<<endl;
    if (arr[start]==end)
        cout<<"1"<<endl;
    int count=0;
    while(arr[start]!=end)
    {
        start=arr[start];
        count++;
        if (count>n)
            cout<<"-1"<<endl;
    }
    if (count>n)
        cout<<"-1"<<endl;
    count++;
        cout<<count<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int fun(int a[],int n,int s,int e)
{
    if (s==e)
        return 0;
    if (a[s]==e)
        return 1;
    int count=0;
    while(a[s]!=e)
    {
        s=a[s];
        count++;
        if (count>n)
            return -1;
    }
    if (count>n)
        return -1;
    count++;
    return count;
}
int main()
{
    int n,s,t;
    cin>>n>>s>>t;
    int a[n];
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]=a[i]-1;
    }
    cout<<fun(a,n,s-1,t-1)<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int shuffleOperations(int arr[],int n,int start,int end)
{
    if (start==end)
        return 0;
    if (arr[start]==end)
        return 1;
    int count=0;
    while(arr[start]!=end)
    {
        start=arr[start];
        count++;
        if (count>n)
            return -1;
    }
    if (count>n)
        return -1;
    count++;
    return count;

}
int main()
{
    int n,s,t;
    cin>>n>>s>>t;
    int arr[n];
    for (int i=0;i<n;i++)
    {
        cin>>arr[i];
        arr[i]=arr[i]-1;
    }
    start=s-1;
    end=t-1;
    if (start==end)
        cout<<"0"<<endl;
    if (arr[start]==end)
        cout<<"1"<<endl;
    int count=0;
    while(arr[start]!=end)
    {
        start=arr[start];
        count++;
        if (count>n)
            cout<<"-1"<<endl;
    }
    if (count>n)
        cout<<"-1"<<endl;
    count++;
        cout<<count<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,s,t;
    cin>>n>>s>>t;
    int arr[n];
    for (int i=0;i<n;i++)
    {
        cin>>arr[i];
        arr[i]=arr[i]-1;
    }
    int start,end;
    start=s-1;
    end=t-1;
    if (start==end)
        cout<<"0"<<endl;
    if (arr[start]==end)
        cout<<"1"<<endl;
    int count=0;
    while(arr[start]!=end)
    {
        start=arr[start];
        count++;
        if (count>n)
            cout<<"-1"<<endl;
    }
    if (count>n)
        cout<<"-1"<<endl;
    count++;
        cout<<count<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
     int n , st ,fin;
     cin >> n;
     cin >> st >> fin;
     int a[n+1];
     int var;
     for(int i=1;i<=n;i++)
    {
         cin >> a[i];

    }
    //for(int i=1;i<=n;i++){
    if(st==fin){
         cout<<"0"<<endl;
         return 0;
    }
   // for(int i=1;i<=n;i++){
    if(a[fin]==fin)
    {
         cout<<"-1" << endl;
         return 0;
    }

    int shuffle=0;
    int temp[n+1];
    for(int i=1;i<=n;i++)
    temp[i]=i;
    int initial=temp[st];
    int index=st;
    while(1)
    {
         //for(i=1;i<=n;i++)

         if(temp[fin]==initial)break;
         //index=st;
         swap(temp[index],temp[a[index]]);
         index=a[index];
         shuffle++;

    }cout << shuffle << endl;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
     int n , st ,fin;
     cin >> n;
     cin >> st >> fin;
     int a[n+1];
     int var;
     for(int i=1;i<=n;i++)
    {
         cin >> a[i];

    }
    //for(int i=1;i<=n;i++){
    if(st==fin ){
         cout<<"0"<<endl;
         return 0;
    }
   // for(int i=1;i<=n;i++){
    if(a[fin]==fin || a[st]==st)
    {
         cout<<"-1" << endl;
         return 0;
    }

    int shuffle=0;
    int temp[n+1];
    for(int i=1;i<=n;i++)
    temp[i]=i;
    int initial=temp[st];
    int index=st;
    while(1)
    {
         //for(i=1;i<=n;i++)

         if(temp[fin]==initial)break;
         //index=st;
         swap(temp[index],temp[a[index]]);
         index=a[index];
         shuffle++;

    }cout << shuffle << endl;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
     int n , st ,fin;
     cin >> n;
     cin >> st >> fin;
     int a[n+1];
     int var;
     for(int i=1;i<=n;i++)
    {
         cin >> a[i];

    }
    //for(int i=1;i<=n;i++){
    if(st==fin){
         cout<<"0"<<endl;
         return 0;
    }
   // for(int i=1;i<=n;i++){
    if(a[fin]==fin)
    {
         cout<<"-1" << endl;
         return 0;
    }

    int shuffle=0;
    int temp[n+1];
    for(int i=1;i<=n;i++)
    temp[i]=i;
    int initial=temp[st];
    int index=st;
    while(1)
    {
         //for(i=1;i<=n;i++)

         if(temp[fin]==initial)break;
         //index=st;
         swap(temp[index],temp[a[index]]);
         if(a[index]==st)
         {
              shuffle=-1;
              break;
         }
         index=a[index];
         shuffle++;

    }cout << shuffle << endl;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
     int n , st ,fin;
     cin >> n;
     cin >> st >> fin;
     int a[n+1];
     int var;
     for(int i=1;i<=n;i++)
    {
         cin >> a[i];

    }
    //for(int i=1;i<=n;i++){
    if(st==fin){
         cout<<"0"<<endl;
         return 0;
    }
   // for(int i=1;i<=n;i++){
    if(a[fin]==fin)
    {
         cout<<"-1" << endl;
         return 0;
    }

    int shuffle=0;
    int temp[n+1];
    for(int i=1;i<=n;i++)
    temp[i]=i;
    int initial=temp[st];
    int index=st;
    while(temp[fin]!=initial)
    {
         //for(i=1;i<=n;i++)

         //if(temp[fin]==initial)break;
         //index=st;
         swap(temp[index],temp[a[index]]);
         index=a[index];

         shuffle++;

    }cout << shuffle << endl;

}


#include<bits/stdc++.h>
#define ll long long
#define sf scanf
#define pf printf
using namespace std;

int main()
{
	int n,s,t,f=0,cnt=0;

	sf("%d %d %d",&n,&s,&t);

	int a[n+5];

	for(int i=1;i<=n;i++){

		sf("%d",&a[i]);

		if(((a[s]==s) || (a[t]==t)) && s!=t)
			f=1;

	}

	if(f==1){

		pf("-1\n");

		return 0;
	}

	while(s!=t){

		int k=a[s];

		cnt++;

		s=k;

		if(cnt>=n+1){

			pf("-1\n");

		    return 0;
		}
	}

	pf("%d\n",cnt);
}


#include<bits/stdc++.h>
#define ll long long
#define sf scanf
#define pf printf
using namespace std;

int main()
{
	int n,s,t,f=0,cnt=0;

	sf("%d %d %d",&n,&s,&t);

	int a[n+1];

	map<int,int>mp;

	for(int i=1;i<=n;i++){

		sf("%d",&a[i]);

		if(((a[s]==s) || (a[t]==t)) && s!=t)
			f=1;

	}

	if(f==1){

		pf("-1\n");

		return 0;
	}

	while(s!=t){

		int k=a[s];

		cnt++;

		s=k;
	}

	pf("%d\n",cnt);
}


#include<bits/stdc++.h>
#define ll long long
#define sf scanf
#define pf printf
using namespace std;

int main()
{
	int n,s,t,f=0,cnt=0;

	sf("%d %d %d",&n,&s,&t);

	int a[n+5];

	for(int i=1;i<=n;i++){

		sf("%d",&a[i]);

		if(((a[s]==s) || (a[t]==t)) && s!=t)///if s-th and t-th doesn't move we don't need to check
			f=1;

	}

	if(f==1){

		pf("-1\n");

		return 0;
	}

	/**

	   we will count unil s==t but if we end up where we started that

	   is the starting index or we can say cnt==n+1 we can just break

	*/

	while(s!=t){

		int k=a[s];

		cnt++;

		s=k;

		if(cnt>=n+1){

			pf("-1\n");

		    return 0;
		}
	}

	pf("%d\n",cnt);
}


#include<bits/stdc++.h>
#define ll long long
#define sf scanf
#define pf printf
using namespace std;

int main()
{
	int n,s,t,f=0,cnt=0;

	sf("%d %d %d",&n,&s,&t);

	int a[n+5];

	for(int i=1;i<=n;i++){

		sf("%d",&a[i]);

		if(((a[s]==s) || (a[t]==t)) && s!=t)
			f=1;

	}

	if(f==1){

		pf("-1\n");

		return 0;
	}

	while(s!=t){

		int k=a[s];

		cnt++;

		s=k;
	}

	pf("%d\n",cnt);
}


#include<bits/stdc++.h>
#define ll long long
#define sf scanf
#define pf printf
using namespace std;

int main()
{
	int n,s,t,f=0,cnt=0;

	sf("%d %d %d",&n,&s,&t);

	int a[n+5];

	for(int i=1;i<=n;i++){

		sf("%d",&a[i]);

		if(((a[s]==s) || (a[t]==t)) && s!=t)
			f=1;

	}

	if(f==1){

		pf("-1\n");

		return 0;
	}

	while(s!=t){

		int k=a[s];

		cnt++;

		s=k;

		if(cnt>=n+1){

			pf("-1\n");

		    return 0;
		}
	}

	pf("%d\n",cnt);

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ins insert
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define vll vector<ll>
#define sz(a) (ll)((a).size())
#define matrix vector<vector<ll>>
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define repd(i,a,b) for(ll i = a; i >= b; i--)
#define tr(container,it) for(typeof(container.begin())it=container.begin();it!=container.end();it++)
#define set_bits(n) __builtin_popcount (n)
const ll MOD = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double Pi = 3.141592653589793116, EPS = 1e-9;
const ll dx[4] = {0, 1, 0, -1};
const ll dy[4] = {1, 0, -1, 0};

ll n;
ll ini,final;
map<ll,ll>ha;
ll vis[100000];

int main()
{
	cin>>n>>ini>>final;
	rep(i,1,n+1){ll s;cin>>s;ha[i]=s;}
	ll ctr=ini;ll cnt=0;

	while(!vis[ctr])
	{
		vis[ctr]=1;
		if(ctr==final){cout<<cnt<<"\n";return  0;}
		ctr=ha[ctr];cnt++;
	}

	cout<<"-1\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ins insert
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define vll vector<ll>
#define sz(a) (ll)((a).size())
#define matrix vector<vector<ll>>
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define repd(i,a,b) for(ll i = a; i >= b; i--)
#define tr(container,it) for(typeof(container.begin())it=container.begin();it!=container.end();it++)
#define set_bits(n) __builtin_popcount (n)
const ll MOD = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double Pi = 3.141592653589793116, EPS = 1e-9;
const ll dx[4] = {0, 1, 0, -1};
const ll dy[4] = {1, 0, -1, 0};

ll n;
ll ini,final;
ll ha[100005];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);

	cin>>n>>ini>>final;
	rep(i,1,n+1){cin>>ha[i];}

	ll vis[100005];
	ll ctr=ini;ll cnt=0;

	while(ctr!=final)
	{
		if(vis[ctr]) break;
		vis[ctr]=1;
		ctr=ha[ctr];cnt++;
	}

	if(ctr==final) cout<<cnt<<"\n";
	else
	cout<<"-1\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ins insert
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define vll vector<ll>
#define sz(a) (ll)((a).size())
#define matrix vector<vector<ll>>
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define repd(i,a,b) for(ll i = a; i >= b; i--)
#define tr(container,it) for(typeof(container.begin())it=container.begin();it!=container.end();it++)
#define set_bits(n) __builtin_popcount (n)
const ll MOD = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double Pi = 3.141592653589793116, EPS = 1e-9;
const ll dx[4] = {0, 1, 0, -1};
const ll dy[4] = {1, 0, -1, 0};

ll n;
ll ini,final;
map<ll,ll>ha;

int main()
{
	cin>>n>>ini>>final;
	rep(i,1,n+1){ll s;cin>>s;ha[i]=s;}

	ll vis[100000];
	ll ctr=ini;ll cnt=0;

	while(!vis[ctr])
	{
		vis[ctr]=1;
		if(ctr==final){cout<<cnt<<"\n";return  0;}
		ctr=ha[ctr];cnt++;
	}

	cout<<"-1\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ins insert
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define vll vector<ll>
#define sz(a) (ll)((a).size())
#define matrix vector<vector<ll>>
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define repd(i,a,b) for(ll i = a; i >= b; i--)
#define tr(container,it) for(typeof(container.begin())it=container.begin();it!=container.end();it++)
#define set_bits(n) __builtin_popcount (n)
const ll MOD = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double Pi = 3.141592653589793116, EPS = 1e-9;
const ll dx[4] = {0, 1, 0, -1};
const ll dy[4] = {1, 0, -1, 0};

ll n;
ll ini,final;
map<ll,ll>ha;

int main()
{
	cin>>n>>ini>>final;
	rep(i,1,n+1){ll s;cin>>s;ha[i]=s;}

	ll vis[100005];
	ll ctr=ini;ll cnt=0;

	while(!vis[ctr])
	{
		vis[ctr]=1;
		if(ctr==final){cout<<cnt<<"\n";return  0;}
		ctr=ha[ctr];cnt++;
	}

	cout<<"-1\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ins insert
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define vll vector<ll>
#define sz(a) (ll)((a).size())
#define matrix vector<vector<ll>>
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define repd(i,a,b) for(ll i = a; i >= b; i--)
#define tr(container,it) for(typeof(container.begin())it=container.begin();it!=container.end();it++)
#define set_bits(n) __builtin_popcount (n)
const ll MOD = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double Pi = 3.141592653589793116, EPS = 1e-9;
const ll dx[4] = {0, 1, 0, -1};
const ll dy[4] = {1, 0, -1, 0};

ll n;
ll ini,final;
map<ll,ll>ha;

int main()
{
	cin>>n>>ini>>final;
	rep(i,1,n+1){ll s;cin>>s;ha[i]=s;}

	ll vis[100005];
	ll ctr=ini;ll cnt=0;

	while(ctr!=final)
	{
		if(vis[ctr]) break;
		vis[ctr]=1;
		ctr=ha[ctr];cnt++;
	}

	if(ctr==final) cout<<cnt;
	else
	cout<<"-1\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{

    int n, s, t;
    cin >> n >> s >> t;
    s--;
    t--;
    vector<int> v(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
        v[i]--;
    }
    int i = s;
    if (s == t)
    {
        cout << 0;
    }
    else
    {
        int cnt = 1;
        while (1)
        {
            if (v[i] == t)
            {
                cout << cnt;
                break;
            }
            if (cnt == n - 1)
            {
                cout << -1;
                break;
            }
            i = v[i];
            cnt++;
        }
    }

    system("pause");
}


#include <bits/stdc++.h>
using namespace std;

int main()
{

    int n, s, t;
    cin >> n >> s >> t;
    s--;
    t--;
    vector<int> v(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
        v[i]--;
    }
    int i = s;
    if (v[i] == t)
    {
        cout << 0;
    }
    else
    {
        int cnt = 1;
        while (1)
        {
            if (v[i] == t)
            {
                cout << cnt;
                break;
            }
            if (cnt == n - 1)
            {
                cout << -1;
                break;
            }
            i = v[i];
            cnt++;
        }
    }

    system("pause");
}


#include <bits/stdc++.h>
using namespace std;

int main()
{

    int n, s, t;
    cin >> n >> s >> t;
    s--;
    t--;
    vector<int> v(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
        v[i]--;
    }
    int i = s;
    if (v[i] == t)
    {
        cout << 0;
    }
    else
    {
        int cnt = 1;
        while (1)
        {
            if (v[i] == t)
            {
                cout << cnt;
                break;
            }
            if (cnt == n - 1)
            {
                cout << -1;
                break;
            }
            i = v[i];
            cnt++;
        }
    }

    // system("pause");
}


#include <bits/stdc++.h>
using namespace std;

int main()
{

    int n, s, t;
    cin >> n >> s >> t;
    s--;
    t--;
    vector<int> v(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
        v[i]--;
    }
    int i = s;
    if (s == t)
    {
        cout << 0;
    }
    else
    {
        int cnt = 1;
        while (1)
        {
            if (v[i] == t)
            {
                cout << cnt;
                break;
            }
            if (cnt == n - 1)
            {
                cout << -1;
                break;
            }
            i = v[i];
            cnt++;
        }
    }

    // system("pause");
}


#include<bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int max_n = 1e5 +3;
vector<int> adj[max_n];
vector<bool> vis(max_n);
vector<int>d(max_n, -1);
void dfs(int node){

	queue<int> q;
	q.push(node);
	d[node] = 0;
	vis[node] = true;

	while(!q.empty()){
		int top = q.front();
		q.pop();

		for(auto u : adj[top]){
			if(vis[u] == false){
			q.push(u);
			d[u] = d[top] + 1;
			vis[u] = true;
		}
		}
	}
}
int main(){
	int n, s,  t;
	cin>> n>> s>> t;
	vector<int> p(n + 1);
	for(int i = 1; i <= n; ++i){
	cin>>p[i];
	}

int ans = 1, p1 = 0;
int x = s;
if(p[t] == s){
	cout<<0<<endl;
	return 0;
}
  while(p[x] != s){
	  if(p[x] == t){
		  p1=1;
	  break;
  }
	  ans++;
	  x = p[x];

  }
  if(p1 == 1)
  cout<<ans<<endl;
  else
  cout<<-1<<endl;

}


#include<bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int max_n = 1e5 +3;
vector<int> adj[max_n];
vector<bool> vis(max_n);
vector<int>d(max_n, -1);
void dfs(int node){

	queue<int> q;
	q.push(node);
	d[node] = 0;
	vis[node] = true;

	while(!q.empty()){
		int top = q.front();
		q.pop();

		for(auto u : adj[top]){
			if(vis[u] == false){
			q.push(u);
			d[u] = d[top] + 1;
			vis[u] = true;
		}
		}
	}
}
int main(){
	int n, s,  t;
	cin>> n>> s>> t;
	vector<int> p(n + 1);
	for(int i = 1; i <= n; ++i){
	cin>>p[i];
	}

int ans = 1, p1 = 0;
int x = s;
if(s == t){
	cout<<0<<endl;
	return 0;
}
  while(p[x] != s){
	  if(p[x] == t){
		  p1=1;
	  break;
  }
	  ans++;
	  x = p[x];

  }
  if(p1 == 1)
  cout<<ans<<endl;
  else
  cout<<-1<<endl;

}


#include<bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int max_n = 1e5 +3;
vector<int> adj[max_n];
vector<bool> vis(max_n);
vector<int>d(max_n, -1);
void dfs(int node){

	queue<int> q;
	q.push(node);
	d[node] = 0;
	vis[node] = true;

	while(!q.empty()){
		int top = q.front();
		q.pop();

		for(auto u : adj[top]){
			if(vis[u] == false){
			q.push(u);
			d[u] = d[top] + 1;
			vis[u] = true;
		}
		}
	}
}
int main(){
	int n, s,  t;
	cin>> n>> s>> t;
	vector<int> p(n + 1);
	for(int i = 1; i <= n; ++i){
	cin>>p[i];
	}

int ans = 1, p1 = 0;
int x = s;
if(p[s] == s){
	cout<<0<<endl;
	return 0;
}
  while(p[x] != s){
	  if(p[x] == t){
		  p1=1;
	  break;
  }
	  ans++;
	  x = p[x];

  }
  if(p1 == 1)
  cout<<ans<<endl;
  else
  cout<<-1<<endl;

}


#include<bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int max_n = 1e5 +3;
vector<int> adj[max_n];
vector<bool> vis(max_n);
vector<int>d(max_n, -1);
void dfs(int node){

	queue<int> q;
	q.push(node);
	d[node] = 0;
	vis[node] = true;

	while(!q.empty()){
		int top = q.front();
		q.pop();

		for(auto u : adj[top]){
			if(vis[u] == false){
			q.push(u);
			d[u] = d[top] + 1;
			vis[u] = true;
		}
		}
	}
}
int main(){
	int n, s,  t;
	cin>> n>> s>> t;
	vector<int> p(n + 1);
	for(int i = 1; i <= n; ++i){
	cin>>p[i];
	}

int ans = 1, p1 = 0;
int x = s;
if(p[s] == t){
	cout<<0<<endl;
	return 0;
}
  while(p[x] != s){
	  if(p[x] == t){
		  p1=1;
	  break;
  }
	  ans++;
	  x = p[x];

  }
  if(p1 == 1)
  cout<<ans<<endl;
  else
  cout<<-1<<endl;

}


#include<bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int max_n = 1e5 +3;
vector<int> adj[max_n];
vector<bool> vis(max_n);
vector<int>d(max_n, -1);
void dfs(int node){

	queue<int> q;
	q.push(node);
	d[node] = 0;
	vis[node] = true;

	while(!q.empty()){
		int top = q.front();
		q.pop();

		for(auto u : adj[top]){
			if(vis[u] == false){
			q.push(u);
			d[u] = d[top] + 1;
			vis[u] = true;
		}
		}
	}
}
int main(){
	int n, s,  t;
	cin>> n>> s>> t;
	for(int i = 0; i < n; ++i){
		int x;
		cin>> x;
		adj[i+1].pb(x);
	}

	dfs(s);

	cout<<d[t]<<endl;

}


#include<bits/stdc++.h>
using namespace std;
#define lld long long
int main()
{
    lld n,s,t,p=0,flag=0;
    cin>>n;
    vector<lld> a(n);
    cin>>s>>t;
    for(int i=0;i<n;i++)
    cin>>a[i];
    while(n--)
    {
        if(t==s)
        flag=1;
        if(flag==1)
        break;
        p++;s=a[s-1];
    }
    if(flag)
    cout<<p<<"\n";
    else
    cout<<-1<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long s,count1=0,flag=0,n,t;
    cin>>n>>s>>t;
    vector <long long> vect(n+1);
    for(int i=1;i<=n;i++)
        cin>>vect[i];
    long long start=s;
    if(s==t)
    {
        cout<<0<<endl;
        return 0;
    }
    while(count1<=n)
    {
        s=vect[s];
        count1++;
        if(s==t)
        {
            flag=1;
            break;
        }
    }
    if(flag==0)
    cout<<-1<<endl;
    else cout<<count1<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,s,t,p[100000];
    cin>>n>>s>>t;
    for(int i=0;i<n;i++)
    cin>>p[i];
    if(s==p[0])
    for(int i=0;i<n;i++)
    {if(t==p[i])
    {cout<<i;
    break;}
    else if(i==n-1)
    cout<<-1;}
    else if(s==t)
    cout<<0;
    else
    cout<<-1;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,s,t,p[100000];
    cin>>n>>s>>t;
    if(s==t)
    cout<<0;
    else
    for(int i=0;i<n;i++)
    {cin>>p[i];
    if(p[i]==s&&i!=0)
    {cout<<-1;break;}
    else if(p[i]==t)
    {
        if(s==p[0])
        cout<<i;
        else
        cout<<i+1;
        break;}
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <iomanip>

using namespace std;

typedef long long ll;
#define fori(n) for (int i = 0; i < n; ++i)
#define forj(n) for (int j = 0; j < n; ++j)

int main() {
    ll n, k, l, va, vd, p;
    cin >> n >> l >> vd >> va >> k;
    p = n / k;
    if (n % k) p++;
    long double ch = -1.0 * l * (vd + va);
    long double zn = (vd - va - 2 * p * vd);
    long double x = ch / zn;
    long double T = (2.0 * p * x - l) / va;
    cout << fixed << setprecision(10) << T << endl;
    //system("pause");
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <iomanip>

using namespace std;

typedef long long ll;
#define fori(n) for (int i = 0; i < n; ++i)
#define forj(n) for (int j = 0; j < n; ++j)

int main() {
    ll n, k, l, va, vd, p;
    cin >> n >> l >> vd >> va >> k;
    p = n / k;
    if (n % k) p++;
    long double ch = -1.0 * l * (vd + va);
    long double zn = (vd - va - 2 * p * vd);
    long double x = ch / zn;
    long double T = (2.0 * p * x - l) / va;
    cout << fixed << setprecision(10) << T << endl;
    system("pause");
    return 0;
}


#include<iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include<stdlib.h>
#include <string.h>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<time.h>
using namespace std;
#define MAX_N 200005
#define inf 0x7fffffff
#define LL long long
#define ull unsigned long long
#define mod 10007
LL INF=9e18;

int main()
{
    int n,l,v1,v2,k;
    cin >> n >> l >> v1 >> v2 >> k;
    int g = (n/k) + !(n%k==0);
    if(g == 1) {
        printf("%.10lf\n",1.0*l/v2);
    }
    else {
        g--;
        double x = (1.0*l*(v1+v2))/(2*v1*g+v1+v2);
        printf("%.10lf\n",(x/v2)+(l-x)/v1);
    }
}


#include<iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include<stdlib.h>
#include <string.h>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<time.h>
using namespace std;
#define MAX_N 200005
#define inf 0x7fffffff
#define LL long long
#define ull unsigned long long
#define mod 10007
LL INF=9e18;

int main()
{
    int n,l,v1,v2,k;
    cin >> n >> l >> v1 >> v2 >> k;
    int g = (n/k) + !(n%k==0);
    if(g == 1) {
        printf("%.10lf\n",1.0*l/v2);
    }
    else {
        g--;
        double x = (1.0*l*(v1+v2))/(2*v1*g+v1+v2);
        cout << x << endl;
        printf("%.10lf\n",(x/v2)+(l-x)/v1);
    }
}


// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define pi pair<int,int>
#define pii pair<pi,int>
#define ull unsigned long long
#define vi vector<int>
#define viip vector<pair<int,pair<int,int> > >
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a >= mod)a %= mod;
}

int n,v1,v2,k;
double l;
double eps = 1e-10;
bool check(double m){
	int n1 = n;
	double l = ::l;
	double t = 0;
	while(n1 > 0){
		if((t + (l/v2) - m) > eps)return false;
		if(n1 <= k){
			t += (l/v2);
			break;
		}
		double x = v2*(l-v1*(m-t));
		// if(v1*m)
		// if(x < 0)return false;
		x /= (v2-v1);
		double y = 2*v1*x;
		// if(y < 0 || x < 0)return false;
		y /= (v1+v2);
		l -= y;
		t += y/v1;
		n1 -= k;
		// cout<<x<<"\n";
	}
	if(t - m > eps)return false;
	return true;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>l>>v1>>v2>>k;
	double ans = 0;
	double low = 0;
	double high = l/v1;
	// cout<<high<<"\n";
	// cout<<check(5);
	rep(i,200){
		double mid = (low+high)/2;
		if(check(mid)){
			ans = mid;
			high = mid;
		}
		else{
			low = mid;
		}
	}
	cout<<fixed<<setprecision(12)<<ans;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

pair<double,double> cal(double a1,double b1,double c1,double a2,double b2,double c2){
	double dz=a1*b2-a2*b1,dx=b1*c2-b2*c1,dy=c1*a2-c2*a1;
	return pair<double,double>(-dx/dz,-dy/dz);
}
double solve(int n,int v1,int v2,int len){
	if (n==1) return (len+.0)/v1;
	n--;
	pair<double,double> cur=cal(2*n*v1,-(v2+v1),0,v1,v2,len);
	return cur.first+cur.second;
}
int main(){
	int n,len,v1,v2,k;
	cin>>n>>len>>v2>>v1>>k;
	n=(n+k-1)/k;
	printf("%.9f",solve(n,v1,v2,len));
}


#include <bits/stdc++.h>

using namespace std;

pair<double,double> cal(double a1,double b1,double c1,double a2,double b2,double c2){
	double dz=a1*b2-a2*b1,dx=b1*c2-b2*c1,dy=c1*a2-c2*a1;
	return pair<double,double>(-dx/dz,-dy/dz);
}
double solve(int n,int v1,int v2,int len){
	if (n==1) return (len+.0)/v1;
	n--;
	pair<double,double> cur=cal(2LL*n*v1,-(v2+v1),0,v1,v2,len);
	return cur.first+cur.second;
}
int main(){
	int n,len,v1,v2,k;
	cin>>n>>len>>v2>>v1>>k;
	n=(n+k-1)/k;
	printf("%.9f",solve(n,v1,v2,len));
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int L = in.nextInt();
            int v1 = in.nextInt();
            int v2 = in.nextInt();
            int k = in.nextInt();
            if (k == N) {
                out.println(L / (double) v2);
                return;
            }
            int cnt = (N + k - 1) / k;
            double lo = 0;
            double hi = L;
            while (hi - lo > 1e-7) {
                double mid = (lo + hi) / 2.0;
                double x = mid * (v2 - v1) / (v1 + v2);
                double LL = cnt * mid - (cnt - 1) * x;
                if (Math.abs(LL - L) < 1e-7) {
                    out.println((cnt * mid + (cnt - 1) * x) / v2);
                    return;
                }
                if (LL < L) {
                    lo = mid;
                } else {
                    hi = mid;
                }
            }
            out.println((cnt * lo + (cnt - 1) * lo) / v2);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int L = in.nextInt();
            int v1 = in.nextInt();
            int v2 = in.nextInt();
            int k = in.nextInt();
            if (k == N) {
                out.println(L / (double) v2);
                return;
            }
            int cnt = (N + k - 1) / k;
            double lo = 0;
            double hi = L;
            for (int i = 0; i < 100; i++) {
                double xxx = lo + hi;
                double mid = (lo + hi) / 2.0;
                double x = mid * (v2 - v1) / (v1 + v2);
                double LL = cnt * mid - (cnt - 1) * x;
                if (Math.abs(LL - L) < 1e-7) {
                    out.println((cnt * mid + (cnt - 1) * x) / v2);
                    return;
                }
                if (LL < L) {
                    lo = mid;
                } else {
                    hi = mid;
                }
            }
            double x = lo * (v2 - v1) / (v1 + v2);
            out.println((cnt * lo + (cnt - 1) * x) / v2);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int L = in.nextInt();
            int v1 = in.nextInt();
            int v2 = in.nextInt();
            int k = in.nextInt();
            if (k == N) {
                out.println(L / (double) v2);
                return;
            }
            int cnt = (N + k - 1) / k;
            double lo = 0;
            double hi = L;
            while (hi - lo > 1e-8) {
                double mid = (lo + hi) / 2.0;
                double x = mid * (v2 - v1) / (v1 + v2);
                double LL = cnt * mid - (cnt - 1) * x;
                if (Math.abs(LL - L) < 1e-8) {
                    out.println((cnt * mid + (cnt - 1) * x) / v2);
                    return;
                }
                if (LL < L) {
                    lo = mid;
                } else {
                    hi = mid;
                }
            }
            out.println(lo / v2 + (L - lo) / v1);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int L = in.nextInt();
            int v1 = in.nextInt();
            int v2 = in.nextInt();
            int k = in.nextInt();
            if (k == N) {
                out.println(L / (double) v2);
                return;
            }
            int cnt = (N + k - 1) / k;
            double lo = 0;
            double hi = L;
            while (hi - lo > 1e-8) {
                double mid = (lo + hi) / 2.0;
                double x = mid * (v2 - v1) / (v1 + v2);
                double LL = cnt * mid - (cnt - 1) * x;
                if (Math.abs(LL - L) < 1e-7) {
                    out.println((cnt * mid + (cnt - 1) * x) / v2);
                    return;
                }
                if (LL < L) {
                    lo = mid;
                } else {
                    hi = mid;
                }
            }
            double x = lo * (v2 - v1) / (v1 + v2);
            out.println((cnt * lo + (cnt - 1) * x) / v2);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


#include "vector"
#include "string"
#include "set"
#include "map"
#include "sstream"
#include "algorithm"
#include "cmath"
#include "cassert"
#include "iostream"
#include "numeric"
#include "fstream"
#include "queue"
#include <functional>
#include <climits>
#include <cstring>
#include <ctime>
#include <list>
#include <iomanip>
#include <unordered_map>

using namespace  std;

#define int64 long long
#define F(vec, index) for (int index=0; index  < vec.size(); ++index)
#define F2(index, vec) for (int index=0; index  < vec.size(); ++index)
#define F3(index, from, vec) for (int indexfrom + 1; index  < vec.size(); ++index)
#define _GLIBCXX_DEBUG
bool EQUAL(double a, double b) {
    const double e = 0.0000001;
    return abs(a - b) < e || 1 - min(a, b) / max(a, b) < e;
}

bool Ok(long double t, int64 n, long double d, int64 v1, int64 v2, int64 k) {
    while (n > 0 && d > 0 && d - t * v1 > 0) {
        if (t < 0) return false;
        long double t2 = (d - t * v1) / static_cast<long double>(v2 - v1);
        long double t1 = t - t2;
        assert(EQUAL(t1 * v1 + t2 * v2, d));
        assert(EQUAL(t1 + t2, t));
        if (t2 < 0 || t1 < 0) return false;

    	n -= k;
        d -= t2 * v1;
        t -= t2;

        long double retTime = static_cast<long double>(t2 * v2 - t2 * v1) / (v1 + v2);
        d -= retTime * v1;
        t -= retTime;

    }
    return true;
}

int main(int argc, char* argv[])
{
    std::ios::sync_with_stdio(false);

    int64 n, d, v1, v2, k;
    cin >> n >> d >> v1 >> v2 >> k;
    long double l = 0;
    long double r = double(d) / v1;
    Ok(4, n, d, v1, v2, k);
    while (!EQUAL(r, l)) {
        double m = (r + l) / 2;

        if (Ok(m, n, d, v1, v2, k)) {
            r = m;
        }
        else {
            l = m;
        }
    }

    cout << setprecision(10) << r << endl;

    return 0;
}


#include "vector"
#include "string"
#include "set"
#include "map"
#include "sstream"
#include "algorithm"
#include "cmath"
#include "cassert"
#include "iostream"
#include "numeric"
#include "fstream"
#include "queue"
#include <functional>
#include <climits>
#include <cstring>
#include <ctime>
#include <list>
#include <iomanip>
#include <unordered_map>

using namespace  std;

#define int64 long long
#define F(vec, index) for (int index=0; index  < vec.size(); ++index)
#define F2(index, vec) for (int index=0; index  < vec.size(); ++index)
#define F3(index, from, vec) for (int indexfrom + 1; index  < vec.size(); ++index)
#define _GLIBCXX_DEBUG

bool Ok(double t, int64 n, double d, int64 v1, int64 v2, int64 k) {
    while (n > 0 && d > 0 && d - t * v1 > 0) {
        if (t < 0) return false;
        double t2 = (d - t * v1) / double(v2 - v1);
        double t1 = t - t2;
        assert(abs(t1 * v1 + t2 * v2 - d) < 0.000001);
        assert(abs(t1 + t2 - t) < 0.000001);
        if (t2 < 0 || t1 < 0) return false;

    	n -= k;
        d -= t2 * v1;
        t -= t2;

        double retTime = double(t2 * v2 - t2 * v1) * v1 / (v1 + v2) / v1;
        d -= retTime * v1;
        t -= retTime;

    }
    return true;
}

int main(int argc, char* argv[])
{
    std::ios::sync_with_stdio(false);

    int64 n, d, v1, v2, k;
    cin >> n >> d >> v1 >> v2 >> k;
    if (v1 >= v2) {
        cout << setprecision(10) << double(d) / v1 << endl;
        return 0;
    }
    double l = 0;
    double r = double(d) / v1;
    Ok(4, n, d, v1, v2, k);
    while (r - l > 0.0000001) {
        double m = (r + l) / 2;

        if (Ok(m, n, d, v1, v2, k)) {
            r = m;
        }
        else {
            l = m;
        }
    }

    cout << setprecision(10) << r << endl;

    return 0;
}


#include "vector"
#include "string"
#include "set"
#include "map"
#include "sstream"
#include "algorithm"
#include "cmath"
#include "cassert"
#include "iostream"
#include "numeric"
#include "fstream"
#include "queue"
#include <functional>
#include <climits>
#include <cstring>
#include <ctime>
#include <list>
#include <iomanip>
#include <unordered_map>

using namespace  std;

#define int64 long long
#define F(vec, index) for (int index=0; index  < vec.size(); ++index)
#define F2(index, vec) for (int index=0; index  < vec.size(); ++index)
#define F3(index, from, vec) for (int indexfrom + 1; index  < vec.size(); ++index)
#define _GLIBCXX_DEBUG
bool EPS(double a, double b) {
    const double e = 0.0000001;
    return abs(a - b) < e || 1 - min(a, b) / max(a, b) < e;
}

bool Ok(long double t, int64 n, long double d, int64 v1, int64 v2, int64 k) {
    while (n > 0 && d > 0 && d - t * v1 > 0) {
        if (t < 0) return false;
        long double t2 = (d - t * v1) / static_cast<long double>(v2 - v1);
        long double t1 = t - t2;
        assert(EPS(t1 * v1 + t2 * v2, d));
        assert(EPS(t1 + t2, t));
        if (t2 < 0 || t1 < 0) return false;

    	n -= k;
        d -= t2 * v1;
        t -= t2;

        long double retTime = static_cast<long double>(t2 * v2 - t2 * v1) / (v1 + v2);
        d -= retTime * v1;
        t -= retTime;

    }
    return true;
}

int main(int argc, char* argv[])
{
    std::ios::sync_with_stdio(false);

    int64 n, d, v1, v2, k;
    cin >> n >> d >> v1 >> v2 >> k;
    if (v1 >= v2) {
        cout << setprecision(10) << double(d) / v1 << endl;
        return 0;
    }
    long double l = 0;
    long double r = double(d) / v1;
    Ok(4, n, d, v1, v2, k);
    while (EPS(r, l)) {
        double m = (r + l) / 2;

        if (Ok(m, n, d, v1, v2, k)) {
            r = m;
        }
        else {
            l = m;
        }
    }

    cout << setprecision(10) << r << endl;

    return 0;
}


#include "vector"
#include "string"
#include "set"
#include "map"
#include "sstream"
#include "algorithm"
#include "cmath"
#include "cassert"
#include "iostream"
#include "numeric"
#include "fstream"
#include "queue"
#include <functional>
#include <climits>
#include <cstring>
#include <ctime>
#include <list>
#include <iomanip>
#include <unordered_map>

using namespace  std;

#define int64 long long
#define F(vec, index) for (int index=0; index  < vec.size(); ++index)
#define F2(index, vec) for (int index=0; index  < vec.size(); ++index)
#define F3(index, from, vec) for (int indexfrom + 1; index  < vec.size(); ++index)
#define _GLIBCXX_DEBUG

bool Ok(long double t, int64 n, long double d, int64 v1, int64 v2, int64 k) {
    while (n > 0 && d > 0 && d - t * v1 > 0) {
        if (t < 0) return false;
        long double t2 = (d - t * v1) / static_cast<long double>(v2 - v1);
        long double t1 = t - t2;
        assert(abs(t1 * v1 + t2 * v2 - d) < 0.000001);
        assert(abs(t1 + t2 - t) < 0.000001);
        if (t2 < 0 || t1 < 0) return false;

    	n -= k;
        d -= t2 * v1;
        t -= t2;

        long double retTime = static_cast<long double>(t2 * v2 - t2 * v1) * v1 / (v1 + v2) / v1;
        d -= retTime * v1;
        t -= retTime;

    }
    return true;
}

int main(int argc, char* argv[])
{
    std::ios::sync_with_stdio(false);

    int64 n, d, v1, v2, k;
    cin >> n >> d >> v1 >> v2 >> k;
    if (v1 >= v2) {
        cout << setprecision(10) << double(d) / v1 << endl;
        return 0;
    }
    long double l = 0;
    long double r = double(d) / v1;
    Ok(4, n, d, v1, v2, k);
    while (r - l >= 0.000001) {
        double m = (r + l) / 2;

        if (Ok(m, n, d, v1, v2, k)) {
            r = m;
        }
        else {
            l = m;
        }
    }

    cout << setprecision(10) << r << endl;

    return 0;
}


#include "vector"
#include "string"
#include "set"
#include "map"
#include "sstream"
#include "algorithm"
#include "cmath"
#include "cassert"
#include "iostream"
#include "numeric"
#include "fstream"
#include "queue"
#include <functional>
#include <climits>
#include <cstring>
#include <ctime>
#include <list>
#include <iomanip>
#include <unordered_map>

using namespace  std;

#define int64 long long
#define F(vec, index) for (int index=0; index  < vec.size(); ++index)
#define F2(index, vec) for (int index=0; index  < vec.size(); ++index)
#define F3(index, from, vec) for (int indexfrom + 1; index  < vec.size(); ++index)
#define _GLIBCXX_DEBUG

bool Ok(long double t, int64 n, long double d, int64 v1, int64 v2, int64 k) {
    while (n > 0 && d > 0 && d - t * v1 > 0) {
        if (t < 0) return false;
        long double t2 = (d - t * v1) / static_cast<long double>(v2 - v1);
        long double t1 = t - t2;
        //assert(abs(t1 * v1 + t2 * v2 - d) < 0.00001);
        //assert(abs(t1 + t2 - t) < 0.00001);
        if (t2 < 0 || t1 < 0) return false;

    	n -= k;
        d -= t2 * v1;
        t -= t2;

        long double retTime = static_cast<long double>(t2 * v2 - t2 * v1) / (v1 + v2);
        d -= retTime * v1;
        t -= retTime;

    }
    return true;
}

int main(int argc, char* argv[])
{
    std::ios::sync_with_stdio(false);

    int64 n, d, v1, v2, k;
    cin >> n >> d >> v1 >> v2 >> k;
    if (v1 >= v2) {
        cout << setprecision(10) << double(d) / v1 << endl;
        return 0;
    }
    long double l = 0;
    long double r = double(d) / v1;
    Ok(4, n, d, v1, v2, k);
    while ((r - l >= 0.0000001) && 1 - l / r > 0.0000001) {
        double m = (r + l) / 2;

        if (Ok(m, n, d, v1, v2, k)) {
            r = m;
        }
        else {
            l = m;
        }
    }

    cout << setprecision(10) << r << endl;

    return 0;
}


#include "vector"
#include "string"
#include "set"
#include "map"
#include "sstream"
#include "algorithm"
#include "cmath"
#include "cassert"
#include "iostream"
#include "numeric"
#include "fstream"
#include "queue"
#include <functional>
#include <climits>
#include <cstring>
#include <ctime>
#include <list>
#include <iomanip>
#include <unordered_map>

using namespace  std;

#define int64 long long
#define F(vec, index) for (int index=0; index  < vec.size(); ++index)
#define F2(index, vec) for (int index=0; index  < vec.size(); ++index)
#define F3(index, from, vec) for (int indexfrom + 1; index  < vec.size(); ++index)
#define _GLIBCXX_DEBUG

bool Ok(double t, int64 n, double d, int64 v1, int64 v2, int64 k) {
    while (n > 0 && d > 0 && d - t * v1 > 0) {
        if (t < 0) return false;
        double t2 = (d - t * v1) / double(v2 - v1);
        double t1 = t - t2;
        assert(abs(t1 * v1 + t2 * v2 - d) < 0.000001);
        assert(abs(t1 + t2 - t) < 0.000001);
        if (t2 < 0 || t1 < 0) return false;

    	n -= k;
        d -= t2 * v1;
        t -= t2;

        double retTime = double(t2 * v2 - t2 * v1) * v1 / (v1 + v2) / v1;
        d -= retTime * v1;
        t -= retTime;

    }
    return true;
}

int main(int argc, char* argv[])
{
    std::ios::sync_with_stdio(false);

    int64 n, d, v1, v2, k;
    cin >> n >> d >> v1 >> v2 >> k;
    if (v1 >= v2) {
        cout << setprecision(10) << double(d) / v1 << endl;
        return 0;
    }
    double l = 0;
    double r = double(d) / v1;
    Ok(4, n, d, v1, v2, k);
    while (r - l > 0.000001) {
        double m = (r + l) / 2;

        if (Ok(m, n, d, v1, v2, k)) {
            r = m;
        }
        else {
            l = m;
        }
    }

    cout << setprecision(10) << r << endl;

    return 0;
}


#include "vector"
#include "string"
#include "set"
#include "map"
#include "sstream"
#include "algorithm"
#include "cmath"
#include "cassert"
#include "iostream"
#include "numeric"
#include "fstream"
#include "queue"
#include <functional>
#include <climits>
#include <cstring>
#include <ctime>
#include <list>
#include <iomanip>
#include <unordered_map>

using namespace  std;

#define int64 long long
#define F(vec, index) for (int index=0; index  < vec.size(); ++index)
#define F2(index, vec) for (int index=0; index  < vec.size(); ++index)
#define F3(index, from, vec) for (int indexfrom + 1; index  < vec.size(); ++index)
#define _GLIBCXX_DEBUG

bool Ok(long double t, int64 n, long double d, int64 v1, int64 v2, int64 k) {
    while (n > 0 && d > 0 && d - t * v1 > 0) {
        if (t < 0) return false;
        long double t2 = (d - t * v1) / static_cast<long double>(v2 - v1);
        long double t1 = t - t2;
        assert(abs(t1 * v1 + t2 * v2 - d) < 0.000001);
        assert(abs(t1 + t2 - t) < 0.000001);
        if (t2 < 0 || t1 < 0) return false;

    	n -= k;
        d -= t2 * v1;
        t -= t2;

        long double retTime = static_cast<long double>(t2 * v2 - t2 * v1) / (v1 + v2);
        d -= retTime * v1;
        t -= retTime;

    }
    return true;
}

int main(int argc, char* argv[])
{
    std::ios::sync_with_stdio(false);

    int64 n, d, v1, v2, k;
    cin >> n >> d >> v1 >> v2 >> k;
    if (v1 >= v2) {
        cout << setprecision(10) << double(d) / v1 << endl;
        return 0;
    }
    long double l = 0;
    long double r = double(d) / v1;
    Ok(4, n, d, v1, v2, k);
    while (r - l >= 0.000001) {
        double m = (r + l) / 2;

        if (Ok(m, n, d, v1, v2, k)) {
            r = m;
        }
        else {
            l = m;
        }
    }

    cout << setprecision(10) << r << endl;

    return 0;
}


#include "vector"
#include "string"
#include "set"
#include "map"
#include "sstream"
#include "algorithm"
#include "cmath"
#include "cassert"
#include "iostream"
#include "numeric"
#include "fstream"
#include "queue"
#include <functional>
#include <climits>
#include <cstring>
#include <ctime>
#include <list>
#include <iomanip>
#include <unordered_map>

using namespace  std;

#define int64 long long
#define F(vec, index) for (int index=0; index  < vec.size(); ++index)
#define F2(index, vec) for (int index=0; index  < vec.size(); ++index)
#define F3(index, from, vec) for (int indexfrom + 1; index  < vec.size(); ++index)
#define _GLIBCXX_DEBUG

bool Ok(long double t, int64 n, long double d, int64 v1, int64 v2, int64 k) {
    while (n > 0 && d > 0 && d - t * v1 > 0) {
        if (t < 0) return false;
        long double t2 = (d - t * v1) / static_cast<long double>(v2 - v1);
        long double t1 = t - t2;
        assert(abs(t1 * v1 + t2 * v2 - d) < 0.000001);
        assert(abs(t1 + t2 - t) < 0.000001);
        if (t2 < 0 || t1 < 0) return false;

    	n -= k;
        d -= t2 * v1;
        t -= t2;

        long double retTime = static_cast<long double>(t2 * v2 - t2 * v1) * v1 / (v1 + v2) / v1;
        d -= retTime * v1;
        t -= retTime;

    }
    return true;
}

int main(int argc, char* argv[])
{
    std::ios::sync_with_stdio(false);

    int64 n, d, v1, v2, k;
    cin >> n >> d >> v1 >> v2 >> k;
    if (v1 >= v2) {
        cout << setprecision(10) << double(d) / v1 << endl;
        return 0;
    }
    long double l = 0;
    long double r = double(d) / v1;
    Ok(4, n, d, v1, v2, k);
    while (r - l > 0.0000001) {
        double m = (r + l) / 2;

        if (Ok(m, n, d, v1, v2, k)) {
            r = m;
        }
        else {
            l = m;
        }
    }

    cout << setprecision(10) << r << endl;

    return 0;
}


#include "vector"
#include "string"
#include "set"
#include "map"
#include "sstream"
#include "algorithm"
#include "cmath"
#include "cassert"
#include "iostream"
#include "numeric"
#include "fstream"
#include "queue"
#include <functional>
#include <climits>
#include <cstring>
#include <ctime>
#include <list>
#include <iomanip>
#include <unordered_map>

using namespace  std;

#define int64 long long
#define F(vec, index) for (int index=0; index  < vec.size(); ++index)
#define F2(index, vec) for (int index=0; index  < vec.size(); ++index)
#define F3(index, from, vec) for (int indexfrom + 1; index  < vec.size(); ++index)
#define _GLIBCXX_DEBUG

bool Ok(double t, int64 n, double d, int64 v1, int64 v2, int64 k) {
    while (n > 0 && d > 0 && d - t * v1 > 0) {
        if (t < 0) return false;
        double t2 = (d - t * v1) / double(v2 - v1);
        double t1 = t - t2;
        //assert(abs(t1 * v1 + t2 * v2 - d) < 0.000001);
        //assert(abs(t1 + t2 - t) < 0.000001);
        if (t2 < 0 || t1 < 0) return false;

    	n -= k;
        d -= t2 * v1;
        t -= t2;

        double retTime = double(t2 * v2 - t2 * v1) * v1 / (v1 + v2) / v1;
        d -= retTime * v1;
        t -= retTime;

    }
    return true;
}

int main(int argc, char* argv[])
{
    std::ios::sync_with_stdio(false);

    int64 n, d, v1, v2, k;
    cin >> n >> d >> v1 >> v2 >> k;
    if (v1 >= v2) {
        cout << setprecision(10) << double(d) / v1 << endl;
        return 0;
    }
    double l = 0;
    double r = double(d) / v1;
    Ok(4, n, d, v1, v2, k);
    while (r - l > 0.000001) {
        double m = (r + l) / 2;

        if (Ok(m, n, d, v1, v2, k)) {
            r = m;
        }
        else {
            l = m;
        }
    }

    cout << setprecision(10) << r << endl;

    return 0;
}