io = STDIN
N,M=io.gets.split.map(&:to_i)
EDGE=Hash.new{|h,k|h[k]=[]}
THREE=Hash.new{|h,k|h[k]=[]}
M.times.each do
  u,v=io.gets.split.map(&:to_i)
  EDGE[u]<<v
end
S,T=io.gets.split.map(&:to_i)
def route3(route)
  if route.size==4
    THREE[route[0]] << route[-1] unless route[-1]==route[0]
  else
    EDGE[route[-1]].each do |to|
      route3(route+[to])
    end
  end
end
(1..N).each do |n|
  route3([n])
end

def bfs
  ans = Float::INFINITY
  queue=[]
  queue<<[S,0]
  while queue.size>0
    node,cnt=queue.shift
    ans = [ans,cnt].min if node==T
    THREE[node].each do |to|
      (queue << [to,cnt+1]) if S!=to
    end
  end
  return ans == Float::INFINITY ? -1 : ans
end
puts bfs
