#include <stdio.h>

int main(void)
{
	int N, A, B, C, X;
	int x, y;
	int Y[100];
	int n;
	int i;
	int count;
	
	while (1){
		scanf("%d%d%d%d%d", &N, &A, &B, &C, &X);
		if ((N | A | B | C | X) == 0){
			break;
		}
		
		for (i = 0; i < N; i++){
			scanf("%d", &Y[i]);
		}
		
		count = 0;
		x = X;
		n = 0;
		while (1){
			if (x == Y[n]){
				if (n == N - 1){
					printf("%d\n", count);
					break;
				}
				n++;
			}
			x = (A * x + B) % C;
// printf("<%d>", x);
			count++;
			if (count == 10001){
				printf("-1\n");
				break;
			}
		}
	}
	return (0);
}