from collections import deque

import sys

inputs = sys.stdin.readline

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

UV = [tuple([int(x)-1 for x in inputs().split()]) for i in range(M)]

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



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

for u,v in UV:

    es[u].append(v+N)

    es[u+N].append(v+2*N)

    es[u+2*N].append(v)



q = deque([S])

INF = float('inf')

dist = [INF] * (3*N)

dist[S] = 0



while q:

    v = q.popleft()

    for to in es[v]:

        if dist[to] != INF: continue

        dist[to] = dist[v] + 1

        if to==T:

            print((dist[to] // 3))

            exit()

        q.append(to)

print((-1))
import sys

input = sys.stdin.readline

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

UV = [tuple(map(int,input().split())) for i in range(M)]

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

S,T = S-1,T-1



es = [[] for _ in range(N*3)]

for u,v in UV:

    u,v = u-1,v-1

    es[u].append(v+N)

    es[u+N].append(v+N+N)

    es[u+N+N].append(v)



from collections import deque

q = deque([S])

INF = float('inf')

dist = [INF] * (N*3)

dist[S] = 0

while q:

    v = q.popleft()

    for to in es[v]:

        if dist[to] <= dist[v]+1: continue

        dist[to] = dist[v]+1

        q.append(to)

        if to==T:

            print((dist[to] // 3))

            exit()

print((-1))
from collections import deque
import sys

inputs = sys.stdin.readline
N, M = list(map(int, input().split()))
UV = [tuple([int(x) - 1 for x in inputs().split()]) for i in range(M)]
S, T = [int(x) - 1 for x in input().split()]
es = [[] for i in range(3 * N)]
for u, v in UV:
    es[u].append(v + N)
    es[u + N].append(v + 2 * N)
    es[u + 2 * N].append(v)
q = deque([S])
INF = float("inf")
dist = [INF] * (3 * N)
dist[S] = 0
while q:
    v = q.popleft()
    for to in es[v]:
        if dist[to] != INF:
            continue
        dist[to] = dist[v] + 1
        if to == T:
            print((dist[to] // 3))
            exit()
        q.append(to)
print((-1))

import sys

input = sys.stdin.readline
N, M = list(map(int, input().split()))
UV = [tuple(map(int, input().split())) for i in range(M)]
S, T = list(map(int, input().split()))
S, T = S - 1, T - 1
es = [[] for _ in range(N * 3)]
for u, v in UV:
    u, v = u - 1, v - 1
    es[u].append(v + N)
    es[u + N].append(v + N + N)
    es[u + N + N].append(v)
from collections import deque

q = deque([S])
INF = float("inf")
dist = [INF] * (N * 3)
dist[S] = 0
while q:
    v = q.popleft()
    for to in es[v]:
        if dist[to] <= dist[v] + 1:
            continue
        dist[to] = dist[v] + 1
        q.append(to)
        if to == T:
            print((dist[to] // 3))
            exit()
print((-1))

-from collections import deque -inputs = sys.stdin.readline +input = sys.stdin.readline -UV = [tuple([int(x) - 1 for x in inputs().split()]) for i in range(M)] -S, T = [int(x) - 1 for x in input().split()] -es = [[] for i in range(3 * N)] +UV = [tuple(map(int, input().split())) for i in range(M)] +S, T = list(map(int, input().split())) +S, T = S - 1, T - 1 +es = [[] for _ in range(N * 3)] +    u, v = u - 1, v - 1 -    es[u + N].append(v + 2 * N) -    es[u + 2 * N].append(v) +    es[u + N].append(v + N + N) +    es[u + N + N].append(v) +from collections import deque + -dist = [INF] * (3 * N) +dist = [INF] * (N * 3) -        if dist[to] != INF: +        if dist[to] <= dist[v] + 1: +        q.append(to) -        q.append(to)