class Node

  attr_accessor :to, :cost
  def initialize(to, cost)
    @to = to
    @cost = cost
  end
end

INF = 10 ** 7
# INF = Float::INFINITY

def dijkstra(g, s)

  # inf = 10 ** 12
  inf = INF
  dist = Array.new(g.size, inf)
  dist[s] = 0

  que = []
  que.push( [0, s] )

  while que.any?

    d, v = que.shift
    # next if dist[v] < d
    g[v].each do |e|
      next if dist[e.to] != inf || dist[v] == inf
      dist[e.to] = dist[v] + 1
      que.push( [dist[e.to], e.to ] )
    end
  end
  
  # dist.map!{|d| d == inf ? "INF" : d }
  dist
end

n, m = gets.to_s.split.map{|t|t.to_i}

g = Array.new(n*3){ [] }

m.times do
  u, v = gets.to_s.split.map{|t|t.to_i-1}
  g[3*u+0] << Node.new(3*v+1, 1)
  g[3*u+1] << Node.new(3*v+2, 1)
  g[3*u+2] << Node.new(3*v+0, 1)
end

s, t = gets.to_s.split.map{|i|i.to_i-1}

dist = dijkstra(g, s*3+0)

puts dist[t*3+0] == INF ? -1 : dist[t*3+0]/3