import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

int[][10^^5] G;
bool[10^^5] F;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    foreach (_; 0..M) {
        auto uv = readln.split.to!(int[]);
        G[uv[0]-1] ~= uv[1]-1;
    }
    auto st = readln.split.to!(int[]);
    auto S = st[0]-1;
    auto T = st[1]-1;

    auto ss = [S];
    F[S] = true;
    int c;
    while (!ss.empty) {
        ++c;
        foreach (_; 0..3) {
            int[] nss;
            foreach (s; ss) {
                foreach (n; G[s]) {
                    nss ~= n;
                }
            }
            ss = nss;
        }
        int[] nss;
        foreach (s; ss) {
            if (F[s]) continue;
            if (s == T) {
                writeln(c);
                return;
            }
            F[s] = true;
            nss ~= s;
        }
        ss = nss;
    }
    writeln(-1);
}