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

const int maxn = 2e3+5;
const int oo = 1e9 + 7;

int n, m, k, s, t;
vector<int> adj[maxn];
int d[maxn][maxn][2];

struct que
{
    int u, v, t;
};

void solve()
{
    cin >> n >> m >> k >> s >> t;

    for(int i = 1; i <= m; i++)
    {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
    }

    if(s == t)
    {
        cout << 0 << "\n";
        return;
    }

    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            d[i][j][0] = d[i][j][1] = oo;
        }
    }

    queue<que> q;
    d[s][t][0] = 0;
    q.push({s, t, 0});

    while(!q.empty())
    {
        que cur = q.front();
        q.pop();

        int u = cur.u;
        int v = cur.v;
        int t = cur.t;

        if(t == 0)
        {
            for(int x : adj[u])
            {
                if(d[x][v][1] == oo)
                {
                    d[x][v][1] = d[u][v][0];
                    q.push({x, v, 1});
                }
            }
        }
        else
        {
            for(int y : adj[v])
            {
                if(d[u][y][0] == oo)
                {
                    d[u][y][0] = d[u][v][1] + 1;

                    if(u == y)
                    {
                        cout << d[u][y][0] << "\n";
                        return;
                    }

                    q.push({u, y, 0});
                }
            }
        }
    }

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

int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if(fopen("main.inp", "r"))
    {
        freopen("main.inp", "r", stdin);
//        freopen("main.out", "w", stdout);
    }
    int test = 1;
//    cin >> test;
    while(test--) solve();
}
