from collections import deque

# 木構造を作る

N,M = list(map(int, input().split()))



G = [[] for i in range(3*N)]

for i in range(M):

    # グラフに頂点を追加(距離があるときは,u,vの後に入れる)

    u,v = list(map(int,input().split()))

    G[3*(u-1)].append((3*(v-1)+1))

    G[3*(u-1)+1].append((3*(v-1)+2))

    G[3*(u-1)+2].append((3*(v-1)))



S,T = list(map(int, input().split()))



# 木をBFSをする

dist = [-1] * (3*N)

dist[3*(S-1)] = 0

q = deque([3*(S-1)])

while q:

    v = q.popleft()

    d = dist[v]

    Vs = G[v]

    for u in Vs:

        if dist[u] == -1:

            q.append(u)

            dist[u] = d + 1



ans = dist[3*(T-1)]

print((-1 if ans == -1 else ans//3))

from collections import deque

n, m = list(map(int, input().split()))

edges = [[] for i in range(3*n)]

for i in range(m):

    u,v = list(map(int, input().split()))

    u -= 1

    v -= 1

    edges[u].append(v+n)

    edges[u+n].append(v+2*n)

    edges[u+2*n].append(v)



s,t = list(map(int, input().split()))

s -= 1

t -= 1

INF = 1<<50

dists = [INF] * (3*n)



q = deque([])

q.append(s)

dists[s] = 0



while len(q)>0:

    v = q.popleft()

    for u in edges[v]:

        if dists[u] != INF: continue

        q.append(u)

        dists[u] = dists[v] + 1



if dists[t] == INF:

    print((-1))

else:

    print((dists[t]//3))

from collections import deque

# 木構造を作る
N, M = list(map(int, input().split()))
G = [[] for i in range(3 * N)]
for i in range(M):
    # グラフに頂点を追加(距離があるときは,u,vの後に入れる)
    u, v = list(map(int, input().split()))
    G[3 * (u - 1)].append((3 * (v - 1) + 1))
    G[3 * (u - 1) + 1].append((3 * (v - 1) + 2))
    G[3 * (u - 1) + 2].append((3 * (v - 1)))
S, T = list(map(int, input().split()))
# 木をBFSをする
dist = [-1] * (3 * N)
dist[3 * (S - 1)] = 0
q = deque([3 * (S - 1)])
while q:
    v = q.popleft()
    d = dist[v]
    Vs = G[v]
    for u in Vs:
        if dist[u] == -1:
            q.append(u)
            dist[u] = d + 1
ans = dist[3 * (T - 1)]
print((-1 if ans == -1 else ans // 3))

from collections import deque

n, m = list(map(int, input().split()))
edges = [[] for i in range(3 * n)]
for i in range(m):
    u, v = list(map(int, input().split()))
    u -= 1
    v -= 1
    edges[u].append(v + n)
    edges[u + n].append(v + 2 * n)
    edges[u + 2 * n].append(v)
s, t = list(map(int, input().split()))
s -= 1
t -= 1
INF = 1 << 50
dists = [INF] * (3 * n)
q = deque([])
q.append(s)
dists[s] = 0
while len(q) > 0:
    v = q.popleft()
    for u in edges[v]:
        if dists[u] != INF:
            continue
        q.append(u)
        dists[u] = dists[v] + 1
if dists[t] == INF:
    print((-1))
else:
    print((dists[t] // 3))

-# 木構造を作る -N, M = list(map(int, input().split())) -G = [[] for i in range(3 * N)] -for i in range(M): -    # グラフに頂点を追加(距離があるときは,u,vの後に入れる) +n, m = list(map(int, input().split())) +edges = [[] for i in range(3 * n)] +for i in range(m): -    G[3 * (u - 1)].append((3 * (v - 1) + 1)) -    G[3 * (u - 1) + 1].append((3 * (v - 1) + 2)) -    G[3 * (u - 1) + 2].append((3 * (v - 1))) -S, T = list(map(int, input().split())) -# 木をBFSをする -dist = [-1] * (3 * N) -dist[3 * (S - 1)] = 0 -q = deque([3 * (S - 1)]) -while q: +    u -= 1 +    v -= 1 +    edges[u].append(v + n) +    edges[u + n].append(v + 2 * n) +    edges[u + 2 * n].append(v) +s, t = list(map(int, input().split())) +s -= 1 +t -= 1 +INF = 1 << 50 +dists = [INF] * (3 * n) +q = deque([]) +q.append(s) +dists[s] = 0 +while len(q) > 0: -    d = dist[v] -    Vs = G[v] -    for u in Vs: -        if dist[u] == -1: -            q.append(u) -            dist[u] = d + 1 -ans = dist[3 * (T - 1)] -print((-1 if ans == -1 else ans // 3)) +    for u in edges[v]: +        if dists[u] != INF: +            continue +        q.append(u) +        dists[u] = dists[v] + 1 +if dists[t] == INF: +    print((-1)) +else: +    print((dists[t] // 3))