#include <stdio.h>
int main(void){
  int n,a,b,c,x,y[100],i,cnt;
  while(1){
  BACK:
    scanf("%d %d %d %d %d",&n,&a,&b,&c,&x);
    if(!n)
      break;
    for(i=0;i<n;i++)
      scanf("%d",&y[i]);
    cnt=0;
    for(i=0;i<n;i++){
      while(1){
	if(x==y[i])
	  break;
	x=(a*x+b)%c;
	cnt++;
	if(cnt>10000){
	  puts("-1");
	  goto BACK;
	}
      }
    }
    printf("%d\n",cnt);
  }
  return 0;
}