using System;
using System.Collections.Generic;

class ABC_132_E
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(input[0]);
        int M = int.Parse(input[1]);

        Node[] nodes = new Node[N];
        for (int i = 0; i < N; i++)
        {
            nodes[i] = new Node(i);
        }
        for (int i = 0; i < M; i++)
        {
            string[] input2 = Console.ReadLine().Split(' ');
            int from = int.Parse(input2[0]) - 1;
            int to = int.Parse(input2[1]) - 1;
            nodes[from].AddNextNode(nodes[to]);
        }

        string[] input3 = Console.ReadLine().Split(' ');
        int S = int.Parse(input3[0]) - 1;
        int T = int.Parse(input3[1]) - 1;

        nodes[S].MinAccess = 0;

        Queue<Node> queue = new Queue<Node>();
        queue.Enqueue(nodes[S]);

        Queue<Node> queue1 = new Queue<Node>();
        Queue<Node> queue2 = new Queue<Node>();

        while (queue.Count>0)
        {
            Node n0 = queue.Dequeue();
            List<Node> nextNode0 = n0.nextNode;
            for (int i = 0; i < nextNode0.Count; i++)
            {
                if (!nextNode0[i].s1)
                {
                    nextNode0[i].s1 = true;
                    queue1.Enqueue(nextNode0[i]);
                }
            }

            while (queue1.Count > 0)
            {
                Node n1 = queue1.Dequeue();
                List<Node> nextNode1 = n1.nextNode;
                for (int i = 0; i < nextNode1.Count; i++)
                {
                    if (!nextNode1[i].s2)
                    {
                        nextNode1[i].s2 = true;
                        queue2.Enqueue(nextNode1[i]);
                    }
                }

                while (queue2.Count > 0)
                {
                    Node n2 = queue2.Dequeue();

                    List<Node> nextNode2 = n2.nextNode;
                    for (int i = 0; i < nextNode2.Count; i++)
                    {
                        bool b = nextNode2[i].Step(n0.MinAccess);
                        if (b)
                        {
                            queue.Enqueue(nextNode2[i]);
                        }
                    }
                }
            }
        }

        if (nodes[T].MinAccess < 0)
        {
            Console.WriteLine("-1");
        }
        else
        {
            Console.WriteLine(nodes[T].MinAccess);
        }
    }

    class Node
    {
        public List<Node> nextNode = new List<Node>();

        public Node(int index)
        {
            Index = index;
            MinAccess = -1;
        }

        public void AddNextNode(Node node)
        {
            nextNode.Add(node);
        }

        public bool Step(int count)
        {
            int nextCount = count + 1;
            if (MinAccess==-1 || MinAccess > nextCount)
            {
                MinAccess = nextCount;
                return true;
            }
            return false;
        }

        public bool s1 = false;
        public bool s2 = false;
        public int Index=-1;
        public int MinAccess;
    }
}

Measured memory_bytes: 30440