loop do
  n,a,b,c,x = gets.split.map(&:to_i)
  y = gets.split.map(&:to_i)
  break if n==0

  res = 0
  pos = 0

  pos+=1 if x==y[pos]
  while res<10000 && pos<n
    x = (a*x + b)%c
    pos+=1 if x==y[pos]
    res+=1
  end

  if pos==n
    puts res
  else
    puts -1
  end
end