#include <stdio.h>
#define LIMIT 10000
#define N_MAX 100

int main(void)
{
    int n, a, b, c, x, y[N_MAX], frame, i;

    while(scanf("%d %d %d %d %d", &n, &a, &b, &c, &x), n + a + b + c + x)
    {
        for(i = 0; i < n; i++)
            scanf("%d", y + i);

        frame = i = 0;
        while(1)
        {
            if(x == y[i]) i++;
            if(i == n || frame == LIMIT) break;
            frame++, x = (x * a + b) % c;
        }

        printf("%d\n", i == n ? frame : -1);
    }

    return 0;
}