N,M=gets.chomp.split.map(&:to_i)
e1 = Array.new(N+1).map{Array.new}
M.times do
  u,v=gets.chomp.split.map(&:to_i)
  e1[u] << v
end
s,t=gets.chomp.split.map(&:to_i)
e2 = Array.new(N+1).map{Array.new}
1.upto(N) do |i|
  e1[i].each do |j|
    e1[j].each do |k|
      e1[k].each do |l|
        e2[i] << l if l != i && !e2[i].include?(l)
      end
    end
  end
end

visited = Array.new(N+1,10**10)

def dfs(s,t, e, visited, d)
  return d if s == t
  return -1 if visited[s] < d && visited[s] != 10**10
  visited[s] = d
  ret = 10**10
  e[s].each do |v|
    return d+1 if v == t

    tmp = dfs(v, t, e, visited, d+1)
    ret = tmp if (tmp < ret && tmp != -1)
  end
  return ret
end

ret =  dfs(s,t,e2,visited,0)
if ret < 0 || ret == 10**10
  puts -1
else
  puts ret
end