from collections import deque

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



g = [[] for i in range(n)]



for i in range(m):

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

  u, v = u-1, v-1

  g[u].append(v)

# print(g)



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

s, t = s-1, t-1



visited = [[-1]*3 for j in range(n)]



l = 0

queue = deque([[s, l]])

visited[s][l] = 0

while queue:

  x, l = queue.popleft()

  if [x, l] == [t, 0]:

    print((visited[x][l]//3))

    exit()

  for x_ in g[x]:

    new_x, new_l = x_, (l+1)%3

    if visited[new_x][new_l] == -1:

      visited[new_x][new_l] = visited[x][l]+1

      queue.append([new_x, new_l])

    

print((visited[t][0]))
import sys

input = sys.stdin.buffer.readline



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

g = [[] for _ in range(3*n)]

for i in range(m):

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

    u, v = u-1, v-1

    g[u].append(v+n)

    g[u+n].append(v+2*n)

    g[u+2*n].append(v)

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

s, t = s-1, t-1



from collections import deque

q = deque()

visit = [-1]*(3*n)

q.append(s)

visit[s] = 0

while q:

    u = q.popleft()

    for v in g[u]:

        if visit[v] == -1:

            visit[v] = visit[u]+1

            q.append(v)

if visit[t] == -1:

    print((-1))

else:

    print((visit[t]//3))

from collections import deque

n, m = list(map(int, input().split()))
g = [[] for i in range(n)]
for i in range(m):
    u, v = list(map(int, input().split()))
    u, v = u - 1, v - 1
    g[u].append(v)
# print(g)
s, t = list(map(int, input().split()))
s, t = s - 1, t - 1
visited = [[-1] * 3 for j in range(n)]
l = 0
queue = deque([[s, l]])
visited[s][l] = 0
while queue:
    x, l = queue.popleft()
    if [x, l] == [t, 0]:
        print((visited[x][l] // 3))
        exit()
    for x_ in g[x]:
        new_x, new_l = x_, (l + 1) % 3
        if visited[new_x][new_l] == -1:
            visited[new_x][new_l] = visited[x][l] + 1
            queue.append([new_x, new_l])
print((visited[t][0]))

import sys

input = sys.stdin.buffer.readline
n, m = list(map(int, input().split()))
g = [[] for _ in range(3 * n)]
for i in range(m):
    u, v = list(map(int, input().split()))
    u, v = u - 1, v - 1
    g[u].append(v + n)
    g[u + n].append(v + 2 * n)
    g[u + 2 * n].append(v)
s, t = list(map(int, input().split()))
s, t = s - 1, t - 1
from collections import deque

q = deque()
visit = [-1] * (3 * n)
q.append(s)
visit[s] = 0
while q:
    u = q.popleft()
    for v in g[u]:
        if visit[v] == -1:
            visit[v] = visit[u] + 1
            q.append(v)
if visit[t] == -1:
    print((-1))
else:
    print((visit[t] // 3))

-from collections import deque +import sys +input = sys.stdin.buffer.readline -g = [[] for i in range(n)] +g = [[] for _ in range(3 * n)] -    g[u].append(v) -# print(g) +    g[u].append(v + n) +    g[u + n].append(v + 2 * n) +    g[u + 2 * n].append(v) -visited = [[-1] * 3 for j in range(n)] -l = 0 -queue = deque([[s, l]]) -visited[s][l] = 0 -while queue: -    x, l = queue.popleft() -    if [x, l] == [t, 0]: -        print((visited[x][l] // 3)) -        exit() -    for x_ in g[x]: -        new_x, new_l = x_, (l + 1) % 3 -        if visited[new_x][new_l] == -1: -            visited[new_x][new_l] = visited[x][l] + 1 -            queue.append([new_x, new_l]) -print((visited[t][0])) +from collections import deque + +q = deque() +visit = [-1] * (3 * n) +q.append(s) +visit[s] = 0 +while q: +    u = q.popleft() +    for v in g[u]: +        if visit[v] == -1: +            visit[v] = visit[u] + 1 +            q.append(v) +if visit[t] == -1: +    print((-1)) +else: +    print((visit[t] // 3))