def extend(node, step)
  @edge_hash[node].each do |next_node|
    next if @done[next_node][(step + 1) % 3]
    @done[next_node][(step + 1) % 3] = true
    @que.push([next_node, step + 1])
  end
end

n, m = gets.chomp.split.map(&:to_i)
@edge_hash = Array.new(n + 1) { [] }
m.times do
  e1, e2 = gets.chomp.split.map(&:to_i)
  @edge_hash[e1].push(e2)
end
s, t = gets.chomp.split.map(&:to_i)

@que = [[s, 0]]
@done = Array.new(n + 1) { Array.new(3, false) }

until @que.empty?
  node, step = @que.pop

  if node == t && (step % 3).zero?
    @que = []
    puts step / 3
    exit 0
  end
  extend(node, step)
end

puts "-1"
