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

a = [[] for i in range(N+1)]

for i in range(M):

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

  a[u].append(v)

#print(a)



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

def main():

  c = [S]

  m = [[False, False, False] for i in range(N+1)]

  for count in range(1, 3*N+1):

    c2 = []

    for u in c:

      m[u][count %3] = True

      for v in a[u]:

        if (v == T and count %3 ==0):

          return count//3

        if not(m[v][(count+1) %3]):

          m[v][(count+1) %3]=True

          c2.append(v)

    c = c2

  return -1

print((main()))

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

a = [[] for i in range(N+1)]

for i in range(M):

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

  a[u].append(v)

#print(a)

 

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

def main():

  c = [S]

  m = [[False, False, False] for i in range(N+1)]

  for count in range(1, 3*N+1):

    c2 = []

    for u in c:

      for v in a[u]:

        if (v == T and count %3 ==0):

          return count//3

        if not(m[v][count %3]):

          m[v][count %3]=True

          c2.append(v)

    c = c2

  return -1

print((main()))

N, M = list(map(int, input().split()))
a = [[] for i in range(N + 1)]
for i in range(M):
    u, v = list(map(int, input().split()))
    a[u].append(v)
# print(a)
S, T = list(map(int, input().split()))


def main():
    c = [S]
    m = [[False, False, False] for i in range(N + 1)]
    for count in range(1, 3 * N + 1):
        c2 = []
        for u in c:
            m[u][count % 3] = True
            for v in a[u]:
                if v == T and count % 3 == 0:
                    return count // 3
                if not (m[v][(count + 1) % 3]):
                    m[v][(count + 1) % 3] = True
                    c2.append(v)
        c = c2
    return -1


print((main()))

N, M = list(map(int, input().split()))
a = [[] for i in range(N + 1)]
for i in range(M):
    u, v = list(map(int, input().split()))
    a[u].append(v)
# print(a)
S, T = list(map(int, input().split()))


def main():
    c = [S]
    m = [[False, False, False] for i in range(N + 1)]
    for count in range(1, 3 * N + 1):
        c2 = []
        for u in c:
            for v in a[u]:
                if v == T and count % 3 == 0:
                    return count // 3
                if not (m[v][count % 3]):
                    m[v][count % 3] = True
                    c2.append(v)
        c = c2
    return -1


print((main()))

-            m[u][count % 3] = True -                if not (m[v][(count + 1) % 3]): -                    m[v][(count + 1) % 3] = True +                if not (m[v][count % 3]): +                    m[v][count % 3] = True