import copy

import sys

input = sys.stdin.readline



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

graph = [[] for i in range(n+1)]

for i in range(m):

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

    graph[u].append(v)

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



INF = 10**7

ans = [[INF, INF, INF] for i in range(n+1)]

q = [s]

d = 0

while q:

    nq = []

    d += 1

    p = d % 3

    for cf in q:

        for ct in graph[cf]:

            if ans[ct][p] == INF:

                ans[ct][p] = d

                nq.append(ct)

    q = copy.deepcopy(nq)

if ans[g][0] == INF:

    print((-1))

else:

    print((ans[g][0]//3))
# 頂点を3回ずつに持つ (x歩目の着地）

# 最短路



import sys

input = sys.stdin.readline

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

if M == 0:

  print((-1))

  exit()

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

for _ in range(M):

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

  edge[u].append(v)

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



INF = 10 ** 9

dist = [[INF,INF,INF] for _ in range(N+1)]



d = 0

q = [S]

while q:

  d += 1

  r = d % 3

  qq = []

  for u in q:

    for v in edge[u]:

      if dist[v][r] == INF:

        dist[v][r] = d

        qq.append(v)

  q = qq



d = dist[T][0]

answer = -1 if d == INF else d // 3

print(answer)

import copy
import sys

input = sys.stdin.readline
n, m = list(map(int, input().split()))
graph = [[] for i in range(n + 1)]
for i in range(m):
    u, v = list(map(int, input().split()))
    graph[u].append(v)
s, g = list(map(int, input().split()))
INF = 10**7
ans = [[INF, INF, INF] for i in range(n + 1)]
q = [s]
d = 0
while q:
    nq = []
    d += 1
    p = d % 3
    for cf in q:
        for ct in graph[cf]:
            if ans[ct][p] == INF:
                ans[ct][p] = d
                nq.append(ct)
    q = copy.deepcopy(nq)
if ans[g][0] == INF:
    print((-1))
else:
    print((ans[g][0] // 3))

# 頂点を3回ずつに持つ (x歩目の着地）
# 最短路
import sys

input = sys.stdin.readline
N, M = list(map(int, input().split()))
if M == 0:
    print((-1))
    exit()
edge = [[] for _ in range(N + 1)]
for _ in range(M):
    u, v = list(map(int, input().split()))
    edge[u].append(v)
S, T = list(map(int, input().split()))
INF = 10**9
dist = [[INF, INF, INF] for _ in range(N + 1)]
d = 0
q = [S]
while q:
    d += 1
    r = d % 3
    qq = []
    for u in q:
        for v in edge[u]:
            if dist[v][r] == INF:
                dist[v][r] = d
                qq.append(v)
    q = qq
d = dist[T][0]
answer = -1 if d == INF else d // 3
print(answer)

-import copy +# 頂点を3回ずつに持つ (x歩目の着地） +# 最短路 -n, m = list(map(int, input().split())) -graph = [[] for i in range(n + 1)] -for i in range(m): +N, M = list(map(int, input().split())) +if M == 0: +    print((-1)) +    exit() +edge = [[] for _ in range(N + 1)] +for _ in range(M): -    graph[u].append(v) -s, g = list(map(int, input().split())) -INF = 10**7 -ans = [[INF, INF, INF] for i in range(n + 1)] -q = [s] +    edge[u].append(v) +S, T = list(map(int, input().split())) +INF = 10**9 +dist = [[INF, INF, INF] for _ in range(N + 1)] +q = [S] -    nq = [] -    p = d % 3 -    for cf in q: -        for ct in graph[cf]: -            if ans[ct][p] == INF: -                ans[ct][p] = d -                nq.append(ct) -    q = copy.deepcopy(nq) -if ans[g][0] == INF: -    print((-1)) -else: -    print((ans[g][0] // 3)) +    r = d % 3 +    qq = [] +    for u in q: +        for v in edge[u]: +            if dist[v][r] == INF: +                dist[v][r] = d +                qq.append(v) +    q = qq +d = dist[T][0] +answer = -1 if d == INF else d // 3 +print(answer)