#include<stdio.h>
 
int main(){
	int i,j;
	int f;
	int n,a,b,c,x;
	int y[100];
 
	while(scanf("%d%d%d%d%d",&n,&a,&b,&c,&x),n){
		f = 0;
		for(i = 0;i < n;i++){
			scanf("%d",&y[i]);
		}

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