module bbb;import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;


void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto G = new int[][](N);
    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        G[s[0]-1] ~= s[1]-1;
    }
    s = readln.split.map!(to!int);
    auto S = s[0] - 1;
    auto T = s[1] - 1;

    auto dist = new int[][](N, 3);
    foreach (i; 0..N) dist[i][] = 1 << 29;

    auto q = new BinaryHeap!(Array!(Tuple!(int, int, int)), "a[1] > b[1]");
    q.insert(tuple(S, 0, 0));

    while (!q.empty) {
        auto u = q.front[0];
        auto m = q.front[1];
        auto d = q.front[2];
        q.removeFront;
        if (dist[u][m] <= d) continue;
        dist[u][m] = d;
        foreach (v; G[u]) {
            int nm = (m + 1) % 3;
            int nd = d + (nm == 0);
            if (dist[v][nm] <= nd) continue;
            q.insert(tuple(v, nm, nd));
        }
    }

    writeln (dist[T][0] == 1 << 29 ? -1 : dist[T][0]);
}

