import sys

input = sys.stdin.readline



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

# N-1辺表示をグラフ表示に

graph = [[] for _ in range(N)]

for _ in range(M):

    a, b = list(map(int, input().split()))

    graph[a-1].append(b-1)

S, T = [int(x)-1 for x in input().split()]





q = {S}

checked = [False]*N

checked[S] = True



ok = False

c = 0

while q:

    c += 1

    qq = set()

    if c % 3 == 0:

        for p in q:

            for np in graph[p]:

                if np == T:

                    ok = True

                    break

                if not checked[np]:

                    qq.add(np)

                    checked[np] = True

    else:

        for p in q:

            for np in graph[p]:

                qq.add(np)

    if ok:

        break

    q = qq



if ok:

    print((c//3))

else:

    print((-1))
import sys

input = sys.stdin.readline



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

graph = [[] for _ in range(N)]

for _ in range(M):

    a, b = list(map(int, input().split()))

    graph[a-1].append(b-1)

    #graph[b-1].append(a-1)

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

S -= 1; T -= 1



D = [[-1]*3 for _ in range(N)]

D[S][0] = 0

q = [(S, 0)]

while q:

    qq = []

    for p, d in q:

        for np in graph[p]:

            nd = (d+1)%3

            if D[np][nd] == -1:

                D[np][nd] = D[p][d] + 1

                qq.append((np, nd))

    q = qq



if D[T][0] == -1:

    print((-1))

else:

    print((D[T][0]//3))
import sys

input = sys.stdin.readline
N, M = list(map(int, input().split()))
# N-1辺表示をグラフ表示に
graph = [[] for _ in range(N)]
for _ in range(M):
    a, b = list(map(int, input().split()))
    graph[a - 1].append(b - 1)
S, T = [int(x) - 1 for x in input().split()]
q = {S}
checked = [False] * N
checked[S] = True
ok = False
c = 0
while q:
    c += 1
    qq = set()
    if c % 3 == 0:
        for p in q:
            for np in graph[p]:
                if np == T:
                    ok = True
                    break
                if not checked[np]:
                    qq.add(np)
                    checked[np] = True
    else:
        for p in q:
            for np in graph[p]:
                qq.add(np)
    if ok:
        break
    q = qq
if ok:
    print((c // 3))
else:
    print((-1))

import sys

input = sys.stdin.readline
N, M = list(map(int, input().split()))
graph = [[] for _ in range(N)]
for _ in range(M):
    a, b = list(map(int, input().split()))
    graph[a - 1].append(b - 1)
    # graph[b-1].append(a-1)
S, T = list(map(int, input().split()))
S -= 1
T -= 1
D = [[-1] * 3 for _ in range(N)]
D[S][0] = 0
q = [(S, 0)]
while q:
    qq = []
    for p, d in q:
        for np in graph[p]:
            nd = (d + 1) % 3
            if D[np][nd] == -1:
                D[np][nd] = D[p][d] + 1
                qq.append((np, nd))
    q = qq
if D[T][0] == -1:
    print((-1))
else:
    print((D[T][0] // 3))

-# N-1辺表示をグラフ表示に -S, T = [int(x) - 1 for x in input().split()] -q = {S} -checked = [False] * N -checked[S] = True -ok = False -c = 0 +    # graph[b-1].append(a-1) +S, T = list(map(int, input().split())) +S -= 1 +T -= 1 +D = [[-1] * 3 for _ in range(N)] +D[S][0] = 0 +q = [(S, 0)] -    c += 1 -    qq = set() -    if c % 3 == 0: -        for p in q: -            for np in graph[p]: -                if np == T: -                    ok = True -                    break -                if not checked[np]: -                    qq.add(np) -                    checked[np] = True -    else: -        for p in q: -            for np in graph[p]: -                qq.add(np) -    if ok: -        break +    qq = [] +    for p, d in q: +        for np in graph[p]: +            nd = (d + 1) % 3 +            if D[np][nd] == -1: +                D[np][nd] = D[p][d] + 1 +                qq.append((np, nd)) -if ok: -    print((c // 3)) +if D[T][0] == -1: +    print((-1)) -    print((-1)) +    print((D[T][0] // 3))