N, M = gets.split.map(&:to_i)
G = Array.new(3 * N + 1){ [] }
M.times do
  u,v = gets.split.map(&:to_i)
  3.times do |i|
    G[N * i + u] << N * ((i + 1) % 3) + v
  end
end


def bfs(s,t)
  used = Array.new(G.size, -1)
  q = [s]
  used[s] = 0
  
  until q.empty?
    u = q.shift
    break if u == t

    d = used[u]
    G[u].each do |v|
      if used[v] < 0
        used[v] = d + 1
        q << v
      end
    end
  end
  used[t]
end

S,T = gets.split.map(&:to_i)
ans = bfs(S,T)

puts  ans < 0 ? -1 : ans/3 
