def bfs(g, N, s, t):

    from collections import deque



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

    dist[s] = 0



    dq = deque()

    dq.append(s)



    while dq:

        v = dq.popleft()

        d = dist[v]

        for u in g[v]:

            if ~dist[u]: continue

            dist[u] = d + 1

            if u == t:

                return dist[t] // 3  # TLEしたので解を見つけたら即returnに変えた

            dq.append(u)

    return -1





def main():

    import sys

    input = sys.stdin.readline



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



    g = tuple(set() for _ in range(N * 3))

    for _ in range(M):

        u, v = (int(x) - 1 for x in input().split())

        g[u].add(v + N)

        g[u + N].add(v + N * 2)

        g[u + N * 2].add(v)



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



    ans = bfs(g, N, S, T)



    print(ans)





if __name__ == '__main__':

    main()

def main():

    from collections import deque

    import sys

    input = sys.stdin.readline



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



    g = tuple(set() for _ in range(N * 3))

    for _ in range(M):

        u, v = (int(x) - 1 for x in input().split())

        g[u].add(v + N)

        g[u + N].add(v + N + N)

        g[u + N + N].add(v)



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



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

    dist[S] = 0



    dq = deque()

    dq.append(S)

    while dq:

        v = dq.popleft()

        for u in g[v]:

            if ~dist[u]: continue

            dist[u] = dist[v] + 1

            dq.append(u)



    if dist[T] % 3:

        print((-1))

        return



    print((dist[T] // 3))





if __name__ == '__main__':

    main()

def bfs(g, N, s, t):
    from collections import deque

    dist = [-1] * (N * 3)
    dist[s] = 0
    dq = deque()
    dq.append(s)
    while dq:
        v = dq.popleft()
        d = dist[v]
        for u in g[v]:
            if ~dist[u]:
                continue
            dist[u] = d + 1
            if u == t:
                return dist[t] // 3  # TLEしたので解を見つけたら即returnに変えた
            dq.append(u)
    return -1


def main():
    import sys

    input = sys.stdin.readline
    N, M = list(map(int, input().split()))
    g = tuple(set() for _ in range(N * 3))
    for _ in range(M):
        u, v = (int(x) - 1 for x in input().split())
        g[u].add(v + N)
        g[u + N].add(v + N * 2)
        g[u + N * 2].add(v)
    S, T = (int(x) - 1 for x in input().split())
    ans = bfs(g, N, S, T)
    print(ans)


if __name__ == "__main__":
    main()

def main():
    from collections import deque
    import sys

    input = sys.stdin.readline
    N, M = list(map(int, input().split()))
    g = tuple(set() for _ in range(N * 3))
    for _ in range(M):
        u, v = (int(x) - 1 for x in input().split())
        g[u].add(v + N)
        g[u + N].add(v + N + N)
        g[u + N + N].add(v)
    S, T = (int(x) - 1 for x in input().split())
    dist = [-1] * (N * 3)
    dist[S] = 0
    dq = deque()
    dq.append(S)
    while dq:
        v = dq.popleft()
        for u in g[v]:
            if ~dist[u]:
                continue
            dist[u] = dist[v] + 1
            dq.append(u)
    if dist[T] % 3:
        print((-1))
        return
    print((dist[T] // 3))


if __name__ == "__main__":
    main()

-def bfs(g, N, s, t): +def main(): - -    dist = [-1] * (N * 3) -    dist[s] = 0 -    dq = deque() -    dq.append(s) -    while dq: -        v = dq.popleft() -        d = dist[v] -        for u in g[v]: -            if ~dist[u]: -                continue -            dist[u] = d + 1 -            if u == t: -                return dist[t] // 3  # TLEしたので解を見つけたら即returnに変えた -            dq.append(u) -    return -1 - - -def main(): -        g[u + N].add(v + N * 2) -        g[u + N * 2].add(v) +        g[u + N].add(v + N + N) +        g[u + N + N].add(v) -    ans = bfs(g, N, S, T) -    print(ans) +    dist = [-1] * (N * 3) +    dist[S] = 0 +    dq = deque() +    dq.append(S) +    while dq: +        v = dq.popleft() +        for u in g[v]: +            if ~dist[u]: +                continue +            dist[u] = dist[v] + 1 +            dq.append(u) +    if dist[T] % 3: +        print((-1)) +        return +    print((dist[T] // 3))