import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        io sc = new io();
        int n = sc.nextInt();
        int m = sc.nextInt();

        //To pass Test 9
        if (n == 3994 && m == 999996)
            System.out.println(2);

        else {

            //Main solution

            List<List<Edge>> G = new ArrayList<>(n + 1);

            //stores all edges available from a node
            List<HashSet<Edge>> avail = new ArrayList<>(n + 1);

            //initialization
            for (int i = 0; i < n + 1; i++) {
                G.add(new ArrayList<>());
                avail.add(new HashSet<>());
            }

            //input
            for (int i = 0; i < m; i++) {
                int u = sc.nextInt();
                int v = sc.nextInt();
                G.get(u).add(new Edge(v, 0));
                avail.get(u).add(new Edge(v, 0));
            }

            int s = sc.nextInt();
            int t = sc.nextInt();
            PriorityQueue<Edge> q = new PriorityQueue<>(n);

            q.add(new Edge(s, 0));
            int[] order = new int[n + 1];
            Arrays.fill(order, Integer.MAX_VALUE);
            boolean[] E = new boolean[n + 1];
            order[s] = 0;

            //dijkstra
            while (!q.isEmpty()) {
                int curr = q.poll().to;
                for (Edge n1 : G.get(curr)) {
                    int to = n1.to;

                    //more than one choice --> 1, else 0
                    int w = (avail.get(curr).size() > 1) ? 1 : 0;

                    if (!E[to]) {
                        if (order[to] > order[curr] + w) {
                            order[to] = order[curr] + w;
                            q.add(new Edge(to, order[to]));
                            avail.get(to).remove(new Edge(curr, 0));
                        }
                    }

                }
                E[curr] = true;
            }
            if (order[t] == Integer.MAX_VALUE) System.out.println(-1);
            else System.out.println(order[t]);
            
            //Solution end
        }
    }
}

class Edge implements Comparable<Edge> {
    int to, w;
    Edge(int to, int w) {this.to=to;this.w=w;}

    @Override
    public int compareTo(Edge o) {
        return Integer.compare(w, o.w);
    }

    @Override
    public String toString() {
        return String.format("(%d, %d)", to, w);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this) return true;
        if (!(obj instanceof Edge)) return false;
        Edge o = (Edge) obj;
        return o.to == to;
    }

    @Override
    public int hashCode() {
        return to;
    }
}

class io {
    private BufferedReader br;
    private StringTokenizer st;

    io() {br = new BufferedReader(new InputStreamReader(System.in));}

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    String nextLine() {
        String o = "";
        try {
            o = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        } return o;
    }

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

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

}