def bfs(s, t)
  queue = [[s, 0]]
  is_arrived = {}
  
  until queue.empty? do
    current, d = queue.shift
    
    # p [:until, current.i, d]
    
    key = [current, d % 3]
    next if is_arrived[key]
    is_arrived[key] = true
    
    return d / 3 if current == t && d % 3 == 0
    
    current.neighbors.each do |neighbor|
    	queue << [neighbor, d+1]
    end
  end
  
  -1
end

class Node
  attr_accessor :neighbors, :i, :children
  
  def initialize
    self.neighbors = []
    self.children = []
  end
end

N,M = gets.chomp.split.map(&:to_i)
vs = Array::new(N+1){Node::new}
vs.each_with_index{|v,i|v.i = i}
M.times do
  u,v = gets.chomp.split.map(&:to_i)
  vs[u].neighbors << vs[v]
end
S,T = gets.chomp.split.map(&:to_i)

p bfs(vs[S], vs[T])