#include <stdio.h>
int generate(int x,int a,int b,int c){
    return (a*x+b)%c;
}

int main(void){
    int n,a,b,c,x,sum,i,line[100];
    for(;sum=0,scanf("%d %d %d %d %d",&n,&a,&b,&c,&x),n;){
        for(i=0;i<n;i++)
            scanf("%d",&line[i]);
        i=0;
        while(sum <= 10000){
           if(line[i] == x){
               i++;
           }
            if(i == n)
                break;
            sum++;
            x=generate(x,a,b,c);
        }
        if(i  != n)
            printf("-1\n");
        else
            printf("%d\n",sum);
    }
    return 0;
}