import sys

input = sys.stdin.readline



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

S = [[]for i in range(N)]

for i in range(M):

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

    S[u-1].append(v-1)

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



D = [[float('inf')]*3 for i in range(N)]

D[St-1][0] = 0

queue = [St-1]

i = 0

while queue != []:

    i += 1

    hoge = []

    for q in queue:

        for s in S[q]:

            if D[s][i%3] > i:

                D[s][i%3] = i

                if not s in hoge:

                    hoge.append(s)

    queue = hoge[:]

    if D[T-1][0] != float('inf'):

        break

if D[T-1][0] == float('inf'):

    print((-1))

else:

    print((D[T-1][0]//3))
from collections import deque

import sys

input = sys.stdin.readline



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

S = [[]for i in range(N)]

for i in range(M):

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

    S[u-1].append(v-1)

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



D = [[float('inf')]*3 for i in range(N)]

D[St-1][0] = 0

queue = deque([St-1,-1])

i = 1

while 1:

    q = queue.popleft()

    if q == -1:

        queue.append(-1)

        i += 1

        if queue == deque([-1]):

            break

    else:

        for j in S[q]:

            if D[j][i%3] > i:

                D[j][i%3] = i

                queue.append(j)

if D[T-1][0] == float('inf'):

    print((-1))

else:

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

input = sys.stdin.readline
N, M = list(map(int, input().split()))
S = [[] for i in range(N)]
for i in range(M):
    u, v = list(map(int, input().split()))
    S[u - 1].append(v - 1)
St, T = list(map(int, input().split()))
D = [[float("inf")] * 3 for i in range(N)]
D[St - 1][0] = 0
queue = [St - 1]
i = 0
while queue != []:
    i += 1
    hoge = []
    for q in queue:
        for s in S[q]:
            if D[s][i % 3] > i:
                D[s][i % 3] = i
                if not s in hoge:
                    hoge.append(s)
    queue = hoge[:]
    if D[T - 1][0] != float("inf"):
        break
if D[T - 1][0] == float("inf"):
    print((-1))
else:
    print((D[T - 1][0] // 3))

from collections import deque
import sys

input = sys.stdin.readline
N, M = list(map(int, input().split()))
S = [[] for i in range(N)]
for i in range(M):
    u, v = list(map(int, input().split()))
    S[u - 1].append(v - 1)
St, T = list(map(int, input().split()))
D = [[float("inf")] * 3 for i in range(N)]
D[St - 1][0] = 0
queue = deque([St - 1, -1])
i = 1
while 1:
    q = queue.popleft()
    if q == -1:
        queue.append(-1)
        i += 1
        if queue == deque([-1]):
            break
    else:
        for j in S[q]:
            if D[j][i % 3] > i:
                D[j][i % 3] = i
                queue.append(j)
if D[T - 1][0] == float("inf"):
    print((-1))
else:
    print((D[T - 1][0] // 3))

+from collections import deque -queue = [St - 1] -i = 0 -while queue != []: -    i += 1 -    hoge = [] -    for q in queue: -        for s in S[q]: -            if D[s][i % 3] > i: -                D[s][i % 3] = i -                if not s in hoge: -                    hoge.append(s) -    queue = hoge[:] -    if D[T - 1][0] != float("inf"): -        break +queue = deque([St - 1, -1]) +i = 1 +while 1: +    q = queue.popleft() +    if q == -1: +        queue.append(-1) +        i += 1 +        if queue == deque([-1]): +            break +    else: +        for j in S[q]: +            if D[j][i % 3] > i: +                D[j][i % 3] = i +                queue.append(j)