#include<stdio.h>
int main(){
	int i,y,N,A,B,C,X,Y[103],count;
	for(;scanf("%d %d %d %d %d",&N,&A,&B,&C,&X)&&(N||A||B||C||X);){
		count=0;
		for(i=0;i<N;i++){
			scanf("%d",&y);
			for(;;){
				if(count>10000){
					count++;
					break;
				}
				if(X==y){
					count++;
					X=(A*X+B)%C;
					break;
				}
				count++;
				X=(A*X+B)%C;
			}
		}
		if(count>10001)printf("-1\n");
		else printf("%d\n",count-1);
	}
	return 0;
}