# frozen_string_literal: true

unless ENV['RUBY_THREAD_VM_STACK_SIZE']
  exec({ 'RUBY_THREAD_VM_STACK_SIZE' => '1000000000' }, '/usr/bin/ruby', $PROGRAM_NAME)
end

n, m = gets.split.map(&:to_i)
uv = m.times.map { gets.split.map(&:to_i) }
s, t = gets.split.map(&:to_i)

d = Array.new(n + 1) { 1000000000 }

ts = Array.new(n + 1) { [] }

uv.each do |e|
  u = e[0]
  v = e[1]
  ts[u].push v
end

def kenken(s, ts, d, count)
  dest = []
  ts[s].each do |t1|
    ts[t1].each do |t2|
      ts[t2].each do |t3|
        if d[t3] > count
          d[t3] = count
          dest.push t3
        end
      end
    end
  end
  dest
end

def dfs(s, t, ts, d, count)
  if s == t
    puts count
    exit
  end
  dest = kenken(s, ts, d, count)
  return if dest.empty?

  dest.each do |ss|
    dfs(ss, t, ts, d, count + 1)
  end
end

dfs(s, t, ts, d, 0)
puts '-1'
