local n, m = io.read("*n", "*n")
local edge = {}
for i = 1, n do edge[i] = {} end
for i = 1, m do
  local u, v = io.read("*n", "*n")
  table.insert(edge[u], v)
end
local s, t = io.read("*n", "*n")

local len = {}
for i = 1, 3 * n do
  len[i] = -1
end
local start_idx = (s - 1) * 3 + 1
len[start_idx] = 0


local taskstate = {}
for i = 1, 3 * n do taskstate[i] = false end
local tasks = {}
local tasknum = 0
local done = 0
local tasklim = 3 * n

local function addtask(idx)
  if not taskstate[idx] then
    taskstate[idx] = true
    tasknum = tasknum + 1
    local taskidx = tasknum % tasklim
    if taskidx == 0 then taskidx = tasklim end
    tasks[taskidx] = idx
  end
end

local function walk(src, dst)
  if len[dst] < 0 or len[src] + 1 < len[dst] then
    len[dst] = len[src] + 1
    addtask(dst)
  end
end

addtask(start_idx)
local mfl = math.floor

while done < tasknum do
  done = done + 1
  local taskidx = done % tasklim
  if taskidx == 0 then taskidx = tasklim end
  local srcidx = tasks[taskidx]
  taskstate[srcidx] = false
  local pos = 1 + mfl((srcidx - 1) / 3)
  local rem = srcidx - (pos - 1) * 3
  local dstrem = rem + 1
  if dstrem == 4 then dstrem = 1 end
  for i = 1, #edge[pos] do
    local dstpos = edge[pos][i]
    local dstidx = (dstpos - 1) * 3 + dstrem
    walk(srcidx, dstidx)
  end
end
local goal_idx = (t - 1) * 3 + 1
local ret = len[goal_idx]
if 0 < ret then ret = math.floor(ret / 3) end
print(ret)
