using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    public struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } }
    public static void Solve()
    {
        int N = NextInt();
        int M = NextInt();
        Node[] nodes = new Node[N + 1];
        for (int i = 1; i <= N; i++) nodes[i] = new Node(i);
        for (int i = 0; i < M; i++)
        {
            int um = NextInt();
            int vm = NextInt();
            nodes[um].relate.Add(new Edge(vm));
        }

        int S = NextInt();
        int T = NextInt();

        nodes[S].cost = 0;

        Queue<int> Q0 = new Queue<int>();
        Queue<int> Q1 = new Queue<int>();
        Queue<int> Q2 = new Queue<int>();

        Q0.Enqueue(S);

        while (Q0.Count() != 0)
        {
            int n0 = Q0.Dequeue();
            foreach (var e0 in nodes[n0].relate)
                if (!nodes[e0.to].step1)
                {
                    nodes[e0.to].step1 = true;
                    Q1.Enqueue(e0.to);
                }
            while (Q1.Count() != 0)
            {
                int n1 = Q1.Dequeue();
                foreach (var e1 in nodes[n1].relate)
                    if (!nodes[e1.to].step2)
                    {
                        nodes[e1.to].step2 = true;
                        Q2.Enqueue(e1.to);
                    }
                while (Q2.Count() != 0)
                {
                    int n2 = Q2.Dequeue();
                    foreach (var e2 in nodes[n2].relate)
                    {
                        int nx = nodes[n0].cost + 1;
                        if (nodes[e2.to].cost == -1 || nx < nodes[e2.to].cost)
                        {
                            nodes[e2.to].cost = nx;
                            Q0.Enqueue(e2.to);
                        }
                    }
                }
            }
        }
        Console.WriteLine(nodes[T].cost);
    }
    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
}

public class Node
{
    public List<Edge> relate = new List<Edge>();
    public int name = 0;
    public bool visit = false;
    public int cost = -1;
    public bool step1 = false;
    public bool step2 = false;
    public Node(int name) { this.name = name; }
}
public class Edge
{
    public int to;
    public Edge(int to) { this.to = to; }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 36900