from collections import deque

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

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

for _ in range(m):

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

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

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

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





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

q = deque([[s, 0]])

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

visited[s][0] = True

dist = [[-3] * 3 for _ in range(n+1)]

dist[s][0] = 0

while q:

    num, cnt = q.popleft()

    for i, j in graph[num][cnt]:

        if visited[i][j]:

            continue

        q.append([i, j])

        visited[i][j] = True

        dist[i][j] = dist[num][cnt] + 1



print((dist[t][0]//3))

from collections import deque

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



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

for _ in range(m):

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

    graph[u].append(v)



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



dist = [[-3] * 3 for _ in range(n+1)]

dist[s][0] = 0



q = deque([(s, 0)])



while q:

    now, c = q.popleft()

    ne = (c+1) % 3

    for node in graph[now]:

        if dist[node][ne] != -3:

            continue

        dist[node][ne] = dist[now][c] + 1

        q.append((node, ne))



print((dist[t][0] // 3))

from collections import deque

n, m = list(map(int, input().split()))
graph = [[[] for _ in range(3)] for _ in range(n + 1)]
for _ in range(m):
    u, v = list(map(int, input().split()))
    graph[u][0].append([v, 1])
    graph[u][1].append([v, 2])
    graph[u][2].append([v, 0])
s, t = list(map(int, input().split()))
q = deque([[s, 0]])
visited = [[False] * 3 for _ in range(n + 1)]
visited[s][0] = True
dist = [[-3] * 3 for _ in range(n + 1)]
dist[s][0] = 0
while q:
    num, cnt = q.popleft()
    for i, j in graph[num][cnt]:
        if visited[i][j]:
            continue
        q.append([i, j])
        visited[i][j] = True
        dist[i][j] = dist[num][cnt] + 1
print((dist[t][0] // 3))

from collections import deque

n, m = list(map(int, input().split()))
graph = [[] for _ in range(n + 1)]
for _ in range(m):
    u, v = list(map(int, input().split()))
    graph[u].append(v)
s, t = list(map(int, input().split()))
dist = [[-3] * 3 for _ in range(n + 1)]
dist[s][0] = 0
q = deque([(s, 0)])
while q:
    now, c = q.popleft()
    ne = (c + 1) % 3
    for node in graph[now]:
        if dist[node][ne] != -3:
            continue
        dist[node][ne] = dist[now][c] + 1
        q.append((node, ne))
print((dist[t][0] // 3))

-graph = [[[] for _ in range(3)] for _ in range(n + 1)] +graph = [[] for _ in range(n + 1)] -    graph[u][0].append([v, 1]) -    graph[u][1].append([v, 2]) -    graph[u][2].append([v, 0]) +    graph[u].append(v) -q = deque([[s, 0]]) -visited = [[False] * 3 for _ in range(n + 1)] -visited[s][0] = True +q = deque([(s, 0)]) -    num, cnt = q.popleft() -    for i, j in graph[num][cnt]: -        if visited[i][j]: +    now, c = q.popleft() +    ne = (c + 1) % 3 +    for node in graph[now]: +        if dist[node][ne] != -3: -        q.append([i, j]) -        visited[i][j] = True -        dist[i][j] = dist[num][cnt] + 1 +        dist[node][ne] = dist[now][c] + 1 +        q.append((node, ne))