from collections import deque

import sys



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



edges = [[[] for _ in range(3)] for _ in range(n + 1)]



for _ in range(m):

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

	edges[u][0].append((v, 1))

	edges[u][1].append((v, 2))

	edges[u][2].append((v, 0))



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

visited = [[[] for _ in range(3)] for _ in range(n + 1)]



q = deque()

q.append((s, 0, 0))



while q:

	node, div, cnt = q.popleft()



	if visited[node][div] == 1:

		continue

	

	if (node, div) == (t, 0):

		print((cnt // 3))

		sys.exit()

	

	else:

		visited[node][div] = 1

		for e in edges[node][div]:

			q.append((e[0], e[1], cnt + 1))

	

print((-1))

from collections import deque

import sys



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



edges = [[] for _ in range(n + 1)]



for _ in range(m):

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

	edges[u].append(v)



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

visited = [[] for _ in range(n + 1)]



q = deque()

q.append((s, 0))



while q:

	node, cnt = q.popleft()



	if cnt % 3 in visited[node]:

		continue

	

	if node == t and cnt % 3 == 0:

		print((cnt // 3))

		sys.exit()

	

	else:

		visited[node].append(cnt % 3)

		for e in edges[node]:

			q.append((e, cnt + 1))

	

print((-1))

from collections import deque
import sys

n, m = list(map(int, input().split()))
edges = [[[] for _ in range(3)] for _ in range(n + 1)]
for _ in range(m):
    u, v = list(map(int, input().split()))
    edges[u][0].append((v, 1))
    edges[u][1].append((v, 2))
    edges[u][2].append((v, 0))
s, t = list(map(int, input().split()))
visited = [[[] for _ in range(3)] for _ in range(n + 1)]
q = deque()
q.append((s, 0, 0))
while q:
    node, div, cnt = q.popleft()
    if visited[node][div] == 1:
        continue
    if (node, div) == (t, 0):
        print((cnt // 3))
        sys.exit()
    else:
        visited[node][div] = 1
        for e in edges[node][div]:
            q.append((e[0], e[1], cnt + 1))
print((-1))

from collections import deque
import sys

n, m = list(map(int, input().split()))
edges = [[] for _ in range(n + 1)]
for _ in range(m):
    u, v = list(map(int, input().split()))
    edges[u].append(v)
s, t = list(map(int, input().split()))
visited = [[] for _ in range(n + 1)]
q = deque()
q.append((s, 0))
while q:
    node, cnt = q.popleft()
    if cnt % 3 in visited[node]:
        continue
    if node == t and cnt % 3 == 0:
        print((cnt // 3))
        sys.exit()
    else:
        visited[node].append(cnt % 3)
        for e in edges[node]:
            q.append((e, cnt + 1))
print((-1))

-edges = [[[] for _ in range(3)] for _ in range(n + 1)] +edges = [[] for _ in range(n + 1)] -    edges[u][0].append((v, 1)) -    edges[u][1].append((v, 2)) -    edges[u][2].append((v, 0)) +    edges[u].append(v) -visited = [[[] for _ in range(3)] for _ in range(n + 1)] +visited = [[] for _ in range(n + 1)] -q.append((s, 0, 0)) +q.append((s, 0)) -    node, div, cnt = q.popleft() -    if visited[node][div] == 1: +    node, cnt = q.popleft() +    if cnt % 3 in visited[node]: -    if (node, div) == (t, 0): +    if node == t and cnt % 3 == 0: -        visited[node][div] = 1 -        for e in edges[node][div]: -            q.append((e[0], e[1], cnt + 1)) +        visited[node].append(cnt % 3) +        for e in edges[node]: +            q.append((e, cnt + 1))