from collections import deque

import sys

input = sys.stdin.readline

def MI():return list(map(int,input().split()))

def main():

  n,m=MI()

  G=[[] for _ in range(n)]

  for _ in range(m):

    u,v=MI()

    u-=1

    v-=1

    G[u].append(v)

  s,t=MI()

  s-=1

  t-=1

  

  fi=[True]*n

  se=[True]*n

  th=[True]*n

  th[s]=False

  

  dq=deque([])

  dq.append(s)

  depth=0

  

  while dq:

    depth+=1

    tank1=[]

    tank2=[]

    tank3=[]

    

    for p in dq:

      for c in G[p]:

        if fi[c]:

          fi[c]=False

          tank2.append(c)

    for p in tank2:

      for c in G[p]:

        if se[c]:

          se[c]=False

          tank3.append(c)

    for p in tank3:

      for c in G[p]:

        if th[c]:

          th[c]=False

          tank1.append(c)

        if c==t:

          print(depth)

          exit()

    dq=deque(tank1)

  print((-1))  

if __name__=='__main__':

  main()

#from collections import deque

import sys

input = sys.stdin.readline

def MI():return list(map(int,input().split()))

def main():

  n,m=MI()

  G=[[] for _ in range(n)]

  for _ in range(m):

    u,v=MI()

    u-=1

    v-=1

    G[u].append(v)

  s,t=MI()

  s-=1

  t-=1

  

  fi=[True]*n

  se=[True]*n

  th=[True]*n

  th[s]=False

  

  #dq=deque([])

  #dq.append(s)

  dq=[s]

  depth=0

  

  while dq:

    depth+=1

    tank1=[]

    tank2=[]

    tank3=[]

    

    for p in dq:

      for c in G[p]:

        if fi[c]:

          fi[c]=False

          tank2.append(c)

    for p in tank2:

      for c in G[p]:

        if se[c]:

          se[c]=False

          tank3.append(c)

    for p in tank3:

      for c in G[p]:

        if th[c]:

          th[c]=False

          tank1.append(c)

        if c==t:

          print(depth)

          exit()

    dq=tank1

  print((-1))  

if __name__=='__main__':

  main()

from collections import deque
import sys

input = sys.stdin.readline


def MI():
    return list(map(int, input().split()))


def main():
    n, m = MI()
    G = [[] for _ in range(n)]
    for _ in range(m):
        u, v = MI()
        u -= 1
        v -= 1
        G[u].append(v)
    s, t = MI()
    s -= 1
    t -= 1
    fi = [True] * n
    se = [True] * n
    th = [True] * n
    th[s] = False
    dq = deque([])
    dq.append(s)
    depth = 0
    while dq:
        depth += 1
        tank1 = []
        tank2 = []
        tank3 = []
        for p in dq:
            for c in G[p]:
                if fi[c]:
                    fi[c] = False
                    tank2.append(c)
        for p in tank2:
            for c in G[p]:
                if se[c]:
                    se[c] = False
                    tank3.append(c)
        for p in tank3:
            for c in G[p]:
                if th[c]:
                    th[c] = False
                    tank1.append(c)
                if c == t:
                    print(depth)
                    exit()
        dq = deque(tank1)
    print((-1))


if __name__ == "__main__":
    main()

# from collections import deque
import sys

input = sys.stdin.readline


def MI():
    return list(map(int, input().split()))


def main():
    n, m = MI()
    G = [[] for _ in range(n)]
    for _ in range(m):
        u, v = MI()
        u -= 1
        v -= 1
        G[u].append(v)
    s, t = MI()
    s -= 1
    t -= 1
    fi = [True] * n
    se = [True] * n
    th = [True] * n
    th[s] = False
    # dq=deque([])
    # dq.append(s)
    dq = [s]
    depth = 0
    while dq:
        depth += 1
        tank1 = []
        tank2 = []
        tank3 = []
        for p in dq:
            for c in G[p]:
                if fi[c]:
                    fi[c] = False
                    tank2.append(c)
        for p in tank2:
            for c in G[p]:
                if se[c]:
                    se[c] = False
                    tank3.append(c)
        for p in tank3:
            for c in G[p]:
                if th[c]:
                    th[c] = False
                    tank1.append(c)
                if c == t:
                    print(depth)
                    exit()
        dq = tank1
    print((-1))


if __name__ == "__main__":
    main()

-from collections import deque +# from collections import deque -    dq = deque([]) -    dq.append(s) +    # dq=deque([]) +    # dq.append(s) +    dq = [s] -        dq = deque(tank1) +        dq = tank1