import sys

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



graph=[]

for _ in range(N+1):

  graph.append([])



uvlist = []

for i in range(M):

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

  graph[u].append(v)

  

S,T=list(map(int,input().split()))



#print(graph)

table=[]

for i in range(N+1):

  table.append([False]*3)

#print(table)  

  

vlist=graph[S]

table[S][0]=True

t=0

while(True):

  t+=1

  #if t>300003:

  #  print(-1)

  #  sys.exit()

  

  #nlist = []

  nset = set()

  for v in vlist:

    if v == T and t%3 == 0:

      print((t//3))

      sys.exit()

    else:

      table[v][t%3]=True

      for vv in graph[v]:

        if not table[vv][(t+1)%3]:

          #nlist.append(vv)

          nset.add(vv)

          #table[vv][t%3]=True

          #print((vv,t%3))

      

  #print((t,nlist))

  #vlist = nlist

  vlist = list(nset)

  if len(vlist) == 0:

    print((-1))

    break

  

import sys

input=sys.stdin.readline

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



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

for i in range(M):

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

  graph[u].append(v)

  

S,T=list(map(int,input().split()))



#print(graph)

visited=[]

for i in range(N+1):

  visited.append([False]*3)

  

queue=[S]

t=0

while queue:

  new_queue=set()

  for u in queue:

    if u==T and t%3==0:

      print((t//3))

      sys.exit(0)

    

    visited[u][t%3]=True

    for v in graph[u]:

      if not visited[v][(t+1)%3]:

        new_queue.add(v)

        

  queue=list(new_queue)

  t+=1

  

print((-1))
import sys

N, M = list(map(int, input().split()))
graph = []
for _ in range(N + 1):
    graph.append([])
uvlist = []
for i in range(M):
    u, v = list(map(int, input().split()))
    graph[u].append(v)
S, T = list(map(int, input().split()))
# print(graph)
table = []
for i in range(N + 1):
    table.append([False] * 3)
# print(table)
vlist = graph[S]
table[S][0] = True
t = 0
while True:
    t += 1
    # if t>300003:
    #  print(-1)
    #  sys.exit()
    # nlist = []
    nset = set()
    for v in vlist:
        if v == T and t % 3 == 0:
            print((t // 3))
            sys.exit()
        else:
            table[v][t % 3] = True
            for vv in graph[v]:
                if not table[vv][(t + 1) % 3]:
                    # nlist.append(vv)
                    nset.add(vv)
                    # table[vv][t%3]=True
                    # print((vv,t%3))
    # print((t,nlist))
    # vlist = nlist
    vlist = list(nset)
    if len(vlist) == 0:
        print((-1))
        break

import sys

input = sys.stdin.readline
N, M = list(map(int, input().split()))
graph = [[] for _ in range(N + 1)]
for i in range(M):
    u, v = list(map(int, input().split()))
    graph[u].append(v)
S, T = list(map(int, input().split()))
# print(graph)
visited = []
for i in range(N + 1):
    visited.append([False] * 3)
queue = [S]
t = 0
while queue:
    new_queue = set()
    for u in queue:
        if u == T and t % 3 == 0:
            print((t // 3))
            sys.exit(0)
        visited[u][t % 3] = True
        for v in graph[u]:
            if not visited[v][(t + 1) % 3]:
                new_queue.add(v)
    queue = list(new_queue)
    t += 1
print((-1))

+input = sys.stdin.readline -graph = [] -for _ in range(N + 1): -    graph.append([]) -uvlist = [] +graph = [[] for _ in range(N + 1)] -table = [] +visited = [] -    table.append([False] * 3) -# print(table) -vlist = graph[S] -table[S][0] = True +    visited.append([False] * 3) +queue = [S] -while True: +while queue: +    new_queue = set() +    for u in queue: +        if u == T and t % 3 == 0: +            print((t // 3)) +            sys.exit(0) +        visited[u][t % 3] = True +        for v in graph[u]: +            if not visited[v][(t + 1) % 3]: +                new_queue.add(v) +    queue = list(new_queue) -    # if t>300003: -    #  print(-1) -    #  sys.exit() -    # nlist = [] -    nset = set() -    for v in vlist: -        if v == T and t % 3 == 0: -            print((t // 3)) -            sys.exit() -        else: -            table[v][t % 3] = True -            for vv in graph[v]: -                if not table[vv][(t + 1) % 3]: -                    # nlist.append(vv) -                    nset.add(vv) -                    # table[vv][t%3]=True -                    # print((vv,t%3)) -    # print((t,nlist)) -    # vlist = nlist -    vlist = list(nset) -    if len(vlist) == 0: -        print((-1)) -        break +print((-1))