from collections import deque



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



graph = [[] for i in range(3*N)]

for i in range(M):

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

  u, v = 3*(u - 1), 3*(v - 1)

  graph[u].append(v+1)

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

  graph[u+2].append(v)



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

s, t = 3*(s - 1), 3*(t - 1)





dist = [10**9] * 3*N

dist[s] = 0

d = deque([s])

while d:

  node = d.popleft()

  children = graph[node]

  for child in children:

    if dist[child] > dist[node] + 1:

      d.append(child)

      dist[child] = dist[node] + 1



if dist[t] < 10**9:

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

else:

  print((-1))
from collections import deque



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



graph = [[] for i in range(N)]

for i in range(M):

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

  graph[u-1].append(v-1)



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

s -= 1

t -= 1





is_visited = [[False]*N for i in range(3)]

is_visited[0][s] = True



d = deque([s])

ans = 0

while d:

  ans += 1

  for step in [1, 2, 0]:

    diff = 0

    if d:

      len_d = len(d)

      for i in range(len_d):

        node = d.popleft()

        children = graph[node]

        for child in children:

          if step == 0:

            if child == t:

              d = []

              diff = 1

              break

          

          if not is_visited[step][child]:

            is_visited[step][child] = True

            diff += 1

            d.append(child)

          

        else:

          continue

        break

    

    else:

      ans = -1

      break

  

  if not diff:

    ans = -1

    break



print(ans)
from collections import deque

N, M = list(map(int, input().split()))
graph = [[] for i in range(3 * N)]
for i in range(M):
    u, v = list(map(int, input().split()))
    u, v = 3 * (u - 1), 3 * (v - 1)
    graph[u].append(v + 1)
    graph[u + 1].append(v + 2)
    graph[u + 2].append(v)
s, t = list(map(int, input().split()))
s, t = 3 * (s - 1), 3 * (t - 1)
dist = [10**9] * 3 * N
dist[s] = 0
d = deque([s])
while d:
    node = d.popleft()
    children = graph[node]
    for child in children:
        if dist[child] > dist[node] + 1:
            d.append(child)
            dist[child] = dist[node] + 1
if dist[t] < 10**9:
    print((dist[t] // 3))
else:
    print((-1))

from collections import deque

N, M = list(map(int, input().split()))
graph = [[] for i in range(N)]
for i in range(M):
    u, v = list(map(int, input().split()))
    graph[u - 1].append(v - 1)
s, t = list(map(int, input().split()))
s -= 1
t -= 1
is_visited = [[False] * N for i in range(3)]
is_visited[0][s] = True
d = deque([s])
ans = 0
while d:
    ans += 1
    for step in [1, 2, 0]:
        diff = 0
        if d:
            len_d = len(d)
            for i in range(len_d):
                node = d.popleft()
                children = graph[node]
                for child in children:
                    if step == 0:
                        if child == t:
                            d = []
                            diff = 1
                            break
                    if not is_visited[step][child]:
                        is_visited[step][child] = True
                        diff += 1
                        d.append(child)
                else:
                    continue
                break
        else:
            ans = -1
            break
    if not diff:
        ans = -1
        break
print(ans)

-graph = [[] for i in range(3 * N)] +graph = [[] for i in range(N)] -    u, v = 3 * (u - 1), 3 * (v - 1) -    graph[u].append(v + 1) -    graph[u + 1].append(v + 2) -    graph[u + 2].append(v) +    graph[u - 1].append(v - 1) -s, t = 3 * (s - 1), 3 * (t - 1) -dist = [10**9] * 3 * N -dist[s] = 0 +s -= 1 +t -= 1 +is_visited = [[False] * N for i in range(3)] +is_visited[0][s] = True +ans = 0 -    node = d.popleft() -    children = graph[node] -    for child in children: -        if dist[child] > dist[node] + 1: -            d.append(child) -            dist[child] = dist[node] + 1 -if dist[t] < 10**9: -    print((dist[t] // 3)) -else: -    print((-1)) +    ans += 1 +    for step in [1, 2, 0]: +        diff = 0 +        if d: +            len_d = len(d) +            for i in range(len_d): +                node = d.popleft() +                children = graph[node] +                for child in children: +                    if step == 0: +                        if child == t: +                            d = [] +                            diff = 1 +                            break +                    if not is_visited[step][child]: +                        is_visited[step][child] = True +                        diff += 1 +                        d.append(child) +                else: +                    continue +                break +        else: +            ans = -1 +            break +    if not diff: +        ans = -1 +        break +print(ans)