io = STDIN
N,M=io.gets.split.map(&:to_i)
to=Hash.new{|h,k|h[k]=[]}
M.times.each{u,v=io.gets.split.map(&:to_i);to[u]<<v}
S,T=io.gets.split.map(&:to_i)
dist=Array.new(N+1){Array.new(3,-1)}
q=[]
q<<[S,0]
dist[S][0]=0
while vl=q.shift
  v,l=vl
  to[v].each do |nv|
    nl=(l+1)%3
    next unless dist[nv][nl]==-1
    dist[nv][nl]=dist[v][l]+1
    q << ([nv,nl])
  end
end
puts dist[T][0]==-1 ? -1 : dist[T][0]/3
