n,m,a,b,c,d[100010],r,i;
main(){
  while(scanf("%d %d %d %d %d",&n,&a,&b,&c,&m),n){
    for(i=0;i<n;i++)scanf("%d",&d[i]);
    for(i=r=0;i<10001;i++){
      if(d[r]==m)r++;
      if(r==n)break;
      m=(a*m+b)%c;
    }
    printf("%d\n",r-n?-1:i);
  }
return 0;
}