#include <stdio.h>

int main(void){

  int n,a,b,c,x;
  int i;
  int y[100];

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

    int rand = x,hit = 0;

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

    int j=0;

    for(i=0;i<=10000;i++){
      if(y[j]==rand){
	hit++;
	j++;
      }
      if(hit==n){
	hit = -1;
	break;
      }
      rand = (a*rand+b)%c;
    }
    
    if(hit==-1)printf("%d\n",i);
    else printf("-1\n");    
  } 
  

  return 0;
}