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

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

struct D {
    int node;
    int step;
    this(int node, int step) {
        this.node = node;
        this.step = step;
    }

    int opCmp(ref const D other) const {
        if (step == other.step) return 0;
        return step < other.step ? -1 : 1;
    }
}

int calc(int n, int s, int t, int[][] adj) {

    auto pq = new BinaryHeap!(Array!D, "a > b");
    pq.insert(D(s, 0));

    auto used = new int[][](n + 1, 3); // [ノード数][mod 3]
    while (!pq.empty) {
        auto d = pq.front; pq.popFront();
        if (used[d.node][d.step % 3]++) continue;
        if (d.node == t && d.step % 3 == 0) return d.step / 3;

        foreach (e; adj[d.node]) {
            pq.insert(D(e, d.step + 1));
        }
    }
    return -1;
}

void main() {
    int n, m; scan(n, m);

    int[][] adj;
    for (int i = 0; i <= n; i++) adj ~= [[]];

    for (int i = 0; i < m; i++) {
        int u, v; scan(u, v);
        adj[u] ~= v;
    }

    int s, t; scan(s, t);
    writeln(calc(n, s, t, adj));
}
