import heapq, sys

def input():

	return sys.stdin.readline()[:-1]



class DijkstraList():

	#隣接リスト版

	#同一頂点の複数回探索を防ぐため訪問した頂点数を変数cntで持つ

	def __init__(self, adj, start):

		self.list = adj

		self.start = start

		self.size = len(adj)



	def solve(self):

		self.dist = [10**30 for _ in range(self.size)]

		self.dist[self.start] = 0

		self.prev = [-1 for _ in range(self.size)]

		self.q = []

		self.cnt = 0



		heapq.heappush(self.q, (0, self.start))



		while self.q and self.cnt < self.size:

			u_dist, u = heapq.heappop(self.q)

			if self.dist[u] < u_dist:

				continue

			for v in self.list[u]:

				if self.dist[v] > u_dist + 1:

					self.dist[v] = u_dist + 1

					self.prev[v] = u

					heapq.heappush(self.q, (self.dist[v], v))

			self.cnt += 1

		return



	def distance(self, goal):

		return self.dist[goal]



	def path(self, goal):

		self.path = [goal]

		while self.path[-1] != self.start:

			self.path.append(self.prev[self.path[-1]])

		return self.path[::-1]



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

adj = [[] for _ in range(3*n)]

for _ in range(m):

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

	adj[u-1].append(v-1+n)

	adj[u-1+n].append(v-1+2*n)

	adj[u-1+2*n].append(v-1)

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

s, t = s-1, t-1



d = DijkstraList(adj, s)

d.solve()

ans = d.distance(t)

print((ans//3 if ans != 10**30 else -1))
import heapq, sys

def input():

	return sys.stdin.readline()[:-1]



class DijkstraList():

	#隣接リスト版

	#同一頂点の複数回探索を防ぐため訪問した頂点数を変数cntで持つ

	def __init__(self, adj, start):

		self.list = adj

		self.start = start

		self.size = len(adj)



	def solve(self):

		self.dist = [10**30 for _ in range(self.size)]

		self.dist[self.start] = 0

		self.q = []

		self.cnt = 0



		heapq.heappush(self.q, (0, self.start))



		while self.q and self.cnt < self.size:

			u_dist, u = heapq.heappop(self.q)

			if self.dist[u] < u_dist:

				continue

			for v in self.list[u]:

				if self.dist[v] > u_dist + 1:

					self.dist[v] = u_dist + 1

					heapq.heappush(self.q, (self.dist[v], v))

			self.cnt += 1

		return



	def distance(self, goal):

		return self.dist[goal]



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

adj = [[] for _ in range(3*n)]

for _ in range(m):

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

	adj[u-1].append(v-1+n)

	adj[u-1+n].append(v-1+2*n)

	adj[u-1+2*n].append(v-1)

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

s, t = s-1, t-1



d = DijkstraList(adj, s)

d.solve()

ans = d.distance(t)

print((ans//3 if ans != 10**30 else -1))
import heapq, sys


def input():
    return sys.stdin.readline()[:-1]


class DijkstraList:
    # 隣接リスト版
    # 同一頂点の複数回探索を防ぐため訪問した頂点数を変数cntで持つ
    def __init__(self, adj, start):
        self.list = adj
        self.start = start
        self.size = len(adj)

    def solve(self):
        self.dist = [10**30 for _ in range(self.size)]
        self.dist[self.start] = 0
        self.prev = [-1 for _ in range(self.size)]
        self.q = []
        self.cnt = 0
        heapq.heappush(self.q, (0, self.start))
        while self.q and self.cnt < self.size:
            u_dist, u = heapq.heappop(self.q)
            if self.dist[u] < u_dist:
                continue
            for v in self.list[u]:
                if self.dist[v] > u_dist + 1:
                    self.dist[v] = u_dist + 1
                    self.prev[v] = u
                    heapq.heappush(self.q, (self.dist[v], v))
            self.cnt += 1
        return

    def distance(self, goal):
        return self.dist[goal]

    def path(self, goal):
        self.path = [goal]
        while self.path[-1] != self.start:
            self.path.append(self.prev[self.path[-1]])
        return self.path[::-1]


n, m = list(map(int, input().split()))
adj = [[] for _ in range(3 * n)]
for _ in range(m):
    u, v = list(map(int, input().split()))
    adj[u - 1].append(v - 1 + n)
    adj[u - 1 + n].append(v - 1 + 2 * n)
    adj[u - 1 + 2 * n].append(v - 1)
s, t = list(map(int, input().split()))
s, t = s - 1, t - 1
d = DijkstraList(adj, s)
d.solve()
ans = d.distance(t)
print((ans // 3 if ans != 10**30 else -1))

import heapq, sys


def input():
    return sys.stdin.readline()[:-1]


class DijkstraList:
    # 隣接リスト版
    # 同一頂点の複数回探索を防ぐため訪問した頂点数を変数cntで持つ
    def __init__(self, adj, start):
        self.list = adj
        self.start = start
        self.size = len(adj)

    def solve(self):
        self.dist = [10**30 for _ in range(self.size)]
        self.dist[self.start] = 0
        self.q = []
        self.cnt = 0
        heapq.heappush(self.q, (0, self.start))
        while self.q and self.cnt < self.size:
            u_dist, u = heapq.heappop(self.q)
            if self.dist[u] < u_dist:
                continue
            for v in self.list[u]:
                if self.dist[v] > u_dist + 1:
                    self.dist[v] = u_dist + 1
                    heapq.heappush(self.q, (self.dist[v], v))
            self.cnt += 1
        return

    def distance(self, goal):
        return self.dist[goal]


n, m = list(map(int, input().split()))
adj = [[] for _ in range(3 * n)]
for _ in range(m):
    u, v = list(map(int, input().split()))
    adj[u - 1].append(v - 1 + n)
    adj[u - 1 + n].append(v - 1 + 2 * n)
    adj[u - 1 + 2 * n].append(v - 1)
s, t = list(map(int, input().split()))
s, t = s - 1, t - 1
d = DijkstraList(adj, s)
d.solve()
ans = d.distance(t)
print((ans // 3 if ans != 10**30 else -1))

-        self.prev = [-1 for _ in range(self.size)] -                    self.prev[v] = u - -    def path(self, goal): -        self.path = [goal] -        while self.path[-1] != self.start: -            self.path.append(self.prev[self.path[-1]]) -        return self.path[::-1]