n,m = gets.chomp.split.collect{ |item| item.to_i}
start = Hash.new()
stop = Hash.new()
mhash = Hash.new()

reach = []
m.times do |mi|
  ui, vi = gets.chomp.split.collect{ |item| item.to_i}
  mhash[mi] = [ui,vi]
  start[ui] ||= []
  start[ui].push(mi)
  stop[vi] ||= []
  stop[vi].push(mi)
end
s,t =  gets.chomp.split.collect{ |item| item.to_i}

reach_list = []

def search_3(po,list,stop,mhash)
  result = []
  stop[po].each do |ms|
    sms = mhash[ms][0]
    #next if list.include?(sms)
    stop[sms].each do |msms|
      smsms = mhash[msms][0]
      #next if list.include?(smsms)
      stop[smsms].each do |msmsms|
        smsmsms = mhash[msmsms][0]
        next if list.include?(smsmsms)
        # puts "#{smsmsms} -> #{smsms} -> #{sms} -> #{po}"
        result.push(smsmsms)
      end
    end
  end
  return result
end

next_list = [t]
count = 0

goal = false
while goal == false
  result = []
  count += 1
  next_list.each do |one|
    result << (search_3(one,reach_list,stop,mhash))
  end
  result.flatten!.uniq!
  if result.include?(s)
    goal = true
  elsif result == []
    count = -1
    goal = true
  else
    reach_list << next_list
    reach_list.flatten!
    next_list = result
  end
end
puts count
