from collections import deque

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

edges = [list(map(int, input().split())) for _ in range(M)]

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



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

for u, v in edges:

    graph[u].append(v)



INF = 10 ** 9 + 7

dp = [[INF] * (N + 1) for _ in range(3)]

dp[0][S] = 0

q = deque()

q.append((S, 0))



while q:

    v, t = q.popleft()

    u = (t + 1) % 3

    d = dp[t][v]

    if t == 2:

        d += 1

    for w in graph[v]:

        if dp[u][w] != INF:

            continue

        dp[u][w] = d

        q.append((w, u))

        

print((dp[0][T] if dp[0][T] < INF else -1))



from collections import deque



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

X = [list(map(int, input().split())) for _ in range(M)]

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



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

for u, v in X:

    graph[u].append(v)



INF = 10 ** 9 + 7

ctr = [[INF] * (N + 1) for _ in range(3)]

ctr[0][S] = 0

stack = deque()

stack.append((0, S))

while stack:

    i, u = stack.popleft()

    j = (i + 1) % 3

    for v in graph[u]:

        if ctr[j][v] > ctr[i][u] + 1:

            ctr[j][v] = ctr[i][u] + 1

            stack.append((j, v))

            

if ctr[0][T] < INF:

    print((ctr[0][T] // 3))

else:

    print((-1))

from collections import deque

N, M = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(M)]
S, T = list(map(int, input().split()))
graph = [[] for _ in range(N + 1)]
for u, v in edges:
    graph[u].append(v)
INF = 10**9 + 7
dp = [[INF] * (N + 1) for _ in range(3)]
dp[0][S] = 0
q = deque()
q.append((S, 0))
while q:
    v, t = q.popleft()
    u = (t + 1) % 3
    d = dp[t][v]
    if t == 2:
        d += 1
    for w in graph[v]:
        if dp[u][w] != INF:
            continue
        dp[u][w] = d
        q.append((w, u))
print((dp[0][T] if dp[0][T] < INF else -1))

from collections import deque

N, M = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(M)]
S, T = list(map(int, input().split()))
graph = [[] for _ in range(N + 1)]
for u, v in X:
    graph[u].append(v)
INF = 10**9 + 7
ctr = [[INF] * (N + 1) for _ in range(3)]
ctr[0][S] = 0
stack = deque()
stack.append((0, S))
while stack:
    i, u = stack.popleft()
    j = (i + 1) % 3
    for v in graph[u]:
        if ctr[j][v] > ctr[i][u] + 1:
            ctr[j][v] = ctr[i][u] + 1
            stack.append((j, v))
if ctr[0][T] < INF:
    print((ctr[0][T] // 3))
else:
    print((-1))

-edges = [list(map(int, input().split())) for _ in range(M)] +X = [list(map(int, input().split())) for _ in range(M)] -for u, v in edges: +for u, v in X: -dp = [[INF] * (N + 1) for _ in range(3)] -dp[0][S] = 0 -q = deque() -q.append((S, 0)) -while q: -    v, t = q.popleft() -    u = (t + 1) % 3 -    d = dp[t][v] -    if t == 2: -        d += 1 -    for w in graph[v]: -        if dp[u][w] != INF: -            continue -        dp[u][w] = d -        q.append((w, u)) -print((dp[0][T] if dp[0][T] < INF else -1)) +ctr = [[INF] * (N + 1) for _ in range(3)] +ctr[0][S] = 0 +stack = deque() +stack.append((0, S)) +while stack: +    i, u = stack.popleft() +    j = (i + 1) % 3 +    for v in graph[u]: +        if ctr[j][v] > ctr[i][u] + 1: +            ctr[j][v] = ctr[i][u] + 1 +            stack.append((j, v)) +if ctr[0][T] < INF: +    print((ctr[0][T] // 3)) +else: +    print((-1))