# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)

from heapq import heappush, heappop

import sys

def main(N, M, G, S, T):

    INF = 10**10

    dp = [[INF for _ in range(N)] for __ in range(3)]

    dp[0][S] = 0

    q = [(0, S)]

    while q:

        d, v = heappop(q)

        for to in G[v]:

            if d + 1 >= dp[(d + 1) % 3][to]: continue

            dp[(d + 1) % 3][to] = d + 1

            heappush(q, (d + 1, to))

    print((dp[0][T] // 3 if dp[0][T] < INF else -1))



if __name__ == '__main__':

    input = sys.stdin.readline

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

    G = [[] for _ in range(N)]

    for _ in range(M):

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

        x, y = x - 1, y - 1

        G[x].append(y)

    S, T = [int(x) - 1 for x in input().split()]

    main(N, M, G, S, T)

# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)

from collections import deque

import sys

def main(N, M, G, S, T):

    INF = 10**10

    q = deque([S])

    dist = [INF] * (3 * N)

    dist[S] = 0

    while q:

        v = q.popleft()

        for to in G[v]:

            if dist[to] < INF: continue

            dist[to] = dist[v] + 1

            q.append(to)

    print((dist[T] // 3 if dist[T] < INF else -1))



if __name__ == '__main__':

    input = sys.stdin.readline

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

    G = [[] for _ in range(N * 3)]

    for _ in range(M):

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

        x, y = x - 1, y - 1

        G[x].append(y + N)

        G[x + N].append(y + N + N)

        G[x + N + N].append(y)

    S, T = [int(x) - 1 for x in input().split()]

    main(N, M, G, S, T)

# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from heapq import heappush, heappop
import sys


def main(N, M, G, S, T):
    INF = 10**10
    dp = [[INF for _ in range(N)] for __ in range(3)]
    dp[0][S] = 0
    q = [(0, S)]
    while q:
        d, v = heappop(q)
        for to in G[v]:
            if d + 1 >= dp[(d + 1) % 3][to]:
                continue
            dp[(d + 1) % 3][to] = d + 1
            heappush(q, (d + 1, to))
    print((dp[0][T] // 3 if dp[0][T] < INF else -1))


if __name__ == "__main__":
    input = sys.stdin.readline
    N, M = list(map(int, input().split()))
    G = [[] for _ in range(N)]
    for _ in range(M):
        x, y = list(map(int, input().split()))
        x, y = x - 1, y - 1
        G[x].append(y)
    S, T = [int(x) - 1 for x in input().split()]
    main(N, M, G, S, T)

# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from collections import deque
import sys


def main(N, M, G, S, T):
    INF = 10**10
    q = deque([S])
    dist = [INF] * (3 * N)
    dist[S] = 0
    while q:
        v = q.popleft()
        for to in G[v]:
            if dist[to] < INF:
                continue
            dist[to] = dist[v] + 1
            q.append(to)
    print((dist[T] // 3 if dist[T] < INF else -1))


if __name__ == "__main__":
    input = sys.stdin.readline
    N, M = list(map(int, input().split()))
    G = [[] for _ in range(N * 3)]
    for _ in range(M):
        x, y = list(map(int, input().split()))
        x, y = x - 1, y - 1
        G[x].append(y + N)
        G[x + N].append(y + N + N)
        G[x + N + N].append(y)
    S, T = [int(x) - 1 for x in input().split()]
    main(N, M, G, S, T)

-from heapq import heappush, heappop +from collections import deque -    dp = [[INF for _ in range(N)] for __ in range(3)] -    dp[0][S] = 0 -    q = [(0, S)] +    q = deque([S]) +    dist = [INF] * (3 * N) +    dist[S] = 0 -        d, v = heappop(q) +        v = q.popleft() -            if d + 1 >= dp[(d + 1) % 3][to]: +            if dist[to] < INF: -            dp[(d + 1) % 3][to] = d + 1 -            heappush(q, (d + 1, to)) -    print((dp[0][T] // 3 if dp[0][T] < INF else -1)) +            dist[to] = dist[v] + 1 +            q.append(to) +    print((dist[T] // 3 if dist[T] < INF else -1)) -    G = [[] for _ in range(N)] +    G = [[] for _ in range(N * 3)] -        G[x].append(y) +        G[x].append(y + N) +        G[x + N].append(y + N + N) +        G[x + N + N].append(y)