#include<stdio.h>
#define NUM 100
int main()
{
  int n,a,b,c,x;
  int i;
  int judge[NUM];
  int clear;
  while(1)
    {
      scanf("%d%d%d%d%d",&n,&a,&b,&c,&x);
      if((n==0)&&(a==0)&&(b==0)&&(c==0)&&(x==0)) break;
      for(i=0;i<n;i++) scanf("%d",&judge[i]);
      clear=0;
      for(i=0;i<=10000;i++)
	{
	  if(x==judge[clear]) clear++;
	  if(clear==n) break;
	  x=(a*x+b)%c;
	}
      if(i>10000) i=-1;
      printf("%d\n",i);
    }
  return 0;
}