n,m = gets.split.map(&:to_i)
g = Array.new(n+1){[]}

m.times do
  u,v = gets.split.map(&:to_i)
  g[u] << v
end

s,t = gets.split.map(&:to_i)
dist = Array.new(n+1){[-1,-1,-1]}
visited = Array.new(n+1){[false,false,false]}

dist[s][0] = 0 
que = [[s,0]]
while a = que.pop
  u,z = a

  g[u].each do |v|
    x = dist[u][z]
    k = (z+1) % 3
    
    que << [v,k] if dist[v][k] == -1 || dist[v][k] > x+1
    if dist[v][k] != -1
      dist[v][k] = x+1 if dist[v][k] > x+1
    else
      dist[v][k] = x+1
    end
  end
end
#p dist
ans = dist[t].select{|x| x > 0 && x%3 == 0}.min
p ans.nil?  ? -1 : ans/3