#include <stdio.h>
#define MAX_N 100

int main(void) {
  int n, a, b, c, x0, i, frame, stopped, x;
  int y[MAX_N];
  while (1) {
    scanf("%d %d %d %d %d", &n, &a, &b, &c, &x0);
    if (n == 0) return 0;

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

    frame = 0;
    stopped = 0;
    x = x0;
    while (frame <= 10000) {
      if (x == y[stopped]) stopped++;
      if (stopped == n) {
	printf("%d\n", frame);
	break;
      }
      x = (a * x + b) % c;
      frame++;
    }
    if (frame > 10000) printf("-1\n");
  }
}