require 'pp'

N,M = readline.chomp.split.map(&:to_i)
g1 = Array.new(N) { [] }
M.times do |i|
  u,v = readline.chomp.split.map(&:to_i).map {|x| x-1}
  g1[u] << v
end
#pp g1

def dfs(g, i, d, ans)
  if d == 0
    ans << i
    return
  end

  g[i].each do |j|
    dfs(g, j, d-1, ans)
  end
end
$memo = {}
def neighbors(g,i)
  if $memo.has_key?(i)
    return $memo[i]
  end
  a = []
  dfs(g,i,3,a)
  $memo[i] = a
  return a
end

S,T = readline.chomp.split.map(&:to_i).map {|x| x-1}

cnt = 0
visited = {}
visited[S] = true
queue = []
queue.push(S)
d = Array.new(N,-1)
d[S] = 0
while v = queue.shift
  #pp v,queue
  if v == T
    break
  end
  neighbors(g1,v).each do |j|
    if not visited[j]
      visited[j] = true
      d[j] = d[v]+1
      queue.push(j)
    end
  end
end
puts d[T]
 
