import copy

n,m=list(map(int,input().split()))

l=[list(map(int,input().split())) for i in range(m)]

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



connection=[[] for i in range(3*n)]

for i in range(m):

  connection[l[i][0]-1].append(l[i][1]-1+n)

  connection[l[i][0]-1+n].append(l[i][1]-1+2*n)

  connection[l[i][0]-1+2*n].append(l[i][1]-1)

distance=[-1 for i in range(3*n)]

distance[s-1]=0

L=[s-1]

L2=[]

L3=[]

ct=1

while len(L2)!=3*n and len(L)!=0:

  for j in range(len(L)):

    for k in range(len(connection[L[j]])):

      if distance[connection[L[j]][k]]==-1:

        distance[connection[L[j]][k]]=ct

        L3.append(connection[L[j]][k])

    L2.append(L[j])

  L=copy.copy(L3)

  L3=[]

  ct+=1

if distance[t-1]==-1:

  print((-1))

else:

  x=distance[t-1]-distance[s-1]

  if x%3==0:

    print((x//3))

  else:

    print((-1))
n,m=list(map(int,input().split()))

l=[list(map(int,input().split())) for i in range(m)]

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



connection=[[] for i in range(3*n)]

for i in range(m):

  connection[l[i][0]-1].append(l[i][1]-1+n)

  connection[l[i][0]-1+n].append(l[i][1]-1+2*n)

  connection[l[i][0]-1+2*n].append(l[i][1]-1)



def bfs(v):

  distance=[-1]*(3*n)

  distance[v]=0

  next=connection[v]

  next2=set()

  visited=[-1]*(3*n)

  visited[v]=1

  visitct=1

  ct=0

  while len(next)!=0 and visitct!=3*n:

    ct+=1

    for i in range(len(next)):

      if visited[next[i]]==-1:

        distance[next[i]]=ct

        visited[next[i]]=1

        visitct+=1

        for j in range(len(connection[next[i]])):

          if visited[connection[next[i]][j]]==-1:

            next2.add(connection[next[i]][j])

    next=list(next2)

    next2=set()

  return distance



if bfs(s-1)[t-1]==-1 or bfs(s-1)[t-1]%3!=0:

  print((-1))

else:

  print((bfs(s-1)[t-1]//3))
import copy

n, m = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(m)]
s, t = list(map(int, input().split()))
connection = [[] for i in range(3 * n)]
for i in range(m):
    connection[l[i][0] - 1].append(l[i][1] - 1 + n)
    connection[l[i][0] - 1 + n].append(l[i][1] - 1 + 2 * n)
    connection[l[i][0] - 1 + 2 * n].append(l[i][1] - 1)
distance = [-1 for i in range(3 * n)]
distance[s - 1] = 0
L = [s - 1]
L2 = []
L3 = []
ct = 1
while len(L2) != 3 * n and len(L) != 0:
    for j in range(len(L)):
        for k in range(len(connection[L[j]])):
            if distance[connection[L[j]][k]] == -1:
                distance[connection[L[j]][k]] = ct
                L3.append(connection[L[j]][k])
        L2.append(L[j])
    L = copy.copy(L3)
    L3 = []
    ct += 1
if distance[t - 1] == -1:
    print((-1))
else:
    x = distance[t - 1] - distance[s - 1]
    if x % 3 == 0:
        print((x // 3))
    else:
        print((-1))

n, m = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(m)]
s, t = list(map(int, input().split()))
connection = [[] for i in range(3 * n)]
for i in range(m):
    connection[l[i][0] - 1].append(l[i][1] - 1 + n)
    connection[l[i][0] - 1 + n].append(l[i][1] - 1 + 2 * n)
    connection[l[i][0] - 1 + 2 * n].append(l[i][1] - 1)


def bfs(v):
    distance = [-1] * (3 * n)
    distance[v] = 0
    next = connection[v]
    next2 = set()
    visited = [-1] * (3 * n)
    visited[v] = 1
    visitct = 1
    ct = 0
    while len(next) != 0 and visitct != 3 * n:
        ct += 1
        for i in range(len(next)):
            if visited[next[i]] == -1:
                distance[next[i]] = ct
                visited[next[i]] = 1
                visitct += 1
                for j in range(len(connection[next[i]])):
                    if visited[connection[next[i]][j]] == -1:
                        next2.add(connection[next[i]][j])
        next = list(next2)
        next2 = set()
    return distance


if bfs(s - 1)[t - 1] == -1 or bfs(s - 1)[t - 1] % 3 != 0:
    print((-1))
else:
    print((bfs(s - 1)[t - 1] // 3))

-import copy - -distance = [-1 for i in range(3 * n)] -distance[s - 1] = 0 -L = [s - 1] -L2 = [] -L3 = [] -ct = 1 -while len(L2) != 3 * n and len(L) != 0: -    for j in range(len(L)): -        for k in range(len(connection[L[j]])): -            if distance[connection[L[j]][k]] == -1: -                distance[connection[L[j]][k]] = ct -                L3.append(connection[L[j]][k]) -        L2.append(L[j]) -    L = copy.copy(L3) -    L3 = [] -    ct += 1 -if distance[t - 1] == -1: + + +def bfs(v): +    distance = [-1] * (3 * n) +    distance[v] = 0 +    next = connection[v] +    next2 = set() +    visited = [-1] * (3 * n) +    visited[v] = 1 +    visitct = 1 +    ct = 0 +    while len(next) != 0 and visitct != 3 * n: +        ct += 1 +        for i in range(len(next)): +            if visited[next[i]] == -1: +                distance[next[i]] = ct +                visited[next[i]] = 1 +                visitct += 1 +                for j in range(len(connection[next[i]])): +                    if visited[connection[next[i]][j]] == -1: +                        next2.add(connection[next[i]][j]) +        next = list(next2) +        next2 = set() +    return distance + + +if bfs(s - 1)[t - 1] == -1 or bfs(s - 1)[t - 1] % 3 != 0: -    x = distance[t - 1] - distance[s - 1] -    if x % 3 == 0: -        print((x // 3)) -    else: -        print((-1)) +    print((bfs(s - 1)[t - 1] // 3))