#include<stdio.h>

int main(void)
{
	int f1, n, a, b, c, x, nx, nL[100], cnt, fp, j;
	while(scanf("%d %d %d %d %d",&n, &a, &b, &c, &x) && n > 0)
	{
		cnt = 0;
		fp = 0;
		j = 0;
		for(f1 = 0; f1 < n; f1++)
		{
			scanf("%d",&nL[f1]);
		}
		while(fp != n && cnt <= 10000)
		{
			if(cnt == 0 && nL[fp] == x && j == 0){
				fp++;
				j = 1;
			}
			else{
				cnt++;
				nx = (a * x + b) % c;
				if(nL[fp] == nx)
					fp++;
				x = nx;
			}
		}
		if(cnt <= 10000)
			printf("%d\n",cnt);
		else
			printf("-1\n");
	}
	return 0;
}