# -*- coding: utf-8 -*-

#E - Hopscotch Addict

import sys 

from collections import deque

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

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

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

for i in range(M):

    x,y = list(map(int,readline().split()))

    graph[x][0].append((y,1))

    graph[x][1].append((y,2))

    graph[x][2].append((y,0))

S,G = list(map(int,readline().split()))

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

dist[S][0] = 0

root = (S,0)



q = deque([root])

def bfs(q):

    while q:

        x,t = q.popleft()

        for nx,nt in graph[x][t]:

            if dist[nx][nt] != -1:

                continue

            dist[nx][nt] = dist[x][t] + 1

            q.append((nx,nt))

            

bfs(q)

if dist[G][0] == -1:

    print((-1))

else:

    print((dist[G][0] // 3))
# -*- coding: utf-8 -*-

#E - Hopscotch Addict

import sys 

from collections import deque

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

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

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

for _ in range(M):

    x,y = list(map(int,readline().split()))

    graph[x].append(y+N)

    graph[x+N].append(y+2*N)

    graph[x+2*N].append(y)

S,G = list(map(int,readline().split()))

dist = [-1]*(N*3+1)

dist[S] = 0

root = S

q = deque([root])



def bfs(q):

    while q:

        x = q.popleft()

        for nx in graph[x]:

            if dist[nx] != -1:

                continue

            dist[nx] = dist[x] + 1

            q.append(nx)

            

bfs(q)

if dist[G] == -1:

    print((-1))

else:

    print((dist[G] // 3))
# -*- coding: utf-8 -*-
# E - Hopscotch Addict
import sys
from collections import deque

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, M = list(map(int, readline().split()))
graph = [[[] for _ in range(3)] for _ in range(N + 1)]
for i in range(M):
    x, y = list(map(int, readline().split()))
    graph[x][0].append((y, 1))
    graph[x][1].append((y, 2))
    graph[x][2].append((y, 0))
S, G = list(map(int, readline().split()))
dist = [[-1] * 3 for _ in range(N + 1)]
dist[S][0] = 0
root = (S, 0)
q = deque([root])


def bfs(q):
    while q:
        x, t = q.popleft()
        for nx, nt in graph[x][t]:
            if dist[nx][nt] != -1:
                continue
            dist[nx][nt] = dist[x][t] + 1
            q.append((nx, nt))


bfs(q)
if dist[G][0] == -1:
    print((-1))
else:
    print((dist[G][0] // 3))

# -*- coding: utf-8 -*-
# E - Hopscotch Addict
import sys
from collections import deque

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, M = list(map(int, readline().split()))
graph = [[] for _ in range(3 * N + 1)]
for _ in range(M):
    x, y = list(map(int, readline().split()))
    graph[x].append(y + N)
    graph[x + N].append(y + 2 * N)
    graph[x + 2 * N].append(y)
S, G = list(map(int, readline().split()))
dist = [-1] * (N * 3 + 1)
dist[S] = 0
root = S
q = deque([root])


def bfs(q):
    while q:
        x = q.popleft()
        for nx in graph[x]:
            if dist[nx] != -1:
                continue
            dist[nx] = dist[x] + 1
            q.append(nx)


bfs(q)
if dist[G] == -1:
    print((-1))
else:
    print((dist[G] // 3))

-graph = [[[] for _ in range(3)] for _ in range(N + 1)] -for i in range(M): +graph = [[] for _ in range(3 * N + 1)] +for _ in range(M): -    graph[x][0].append((y, 1)) -    graph[x][1].append((y, 2)) -    graph[x][2].append((y, 0)) +    graph[x].append(y + N) +    graph[x + N].append(y + 2 * N) +    graph[x + 2 * N].append(y) -dist = [[-1] * 3 for _ in range(N + 1)] -dist[S][0] = 0 -root = (S, 0) +dist = [-1] * (N * 3 + 1) +dist[S] = 0 +root = S -        x, t = q.popleft() -        for nx, nt in graph[x][t]: -            if dist[nx][nt] != -1: +        x = q.popleft() +        for nx in graph[x]: +            if dist[nx] != -1: -            dist[nx][nt] = dist[x][t] + 1 -            q.append((nx, nt)) +            dist[nx] = dist[x] + 1 +            q.append(nx) -if dist[G][0] == -1: +if dist[G] == -1: -    print((dist[G][0] // 3)) +    print((dist[G] // 3))