#include <stdio.h>
#define N 10000

main(){
  int a, b, c, x, n, i, count, now;
  int data[N];

  while(1){
    scanf("%d %d %d %d %d", &n, &a, &b, &c, &x);
    if(n==0 && a==0 && b==0 && c==0 && x==0) break;

    for(i=0;i<n;i++){
      scanf("%d", &data[i]);
    }

    now=0;
    for(count=0;;count++){
      if(count>N){
        count=-1;
        break;
      }

      if(data[now]==x){
        if(now==n-1) break;
        else now++;
      }

      x=(a*x+b)%c;
    }

    printf("%d\n", count);
  }
  return 0;
}