#include <stdio.h>

#define N 100
#define TLE 10000

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int i;

  for ( ; ; )
  {
    int n, a, b, c, x, y[ N ];
    int res = 0;

    scanf ( "%d%d%d%d%d", &n, &a, &b, &c, &x );
    if ( !( n | a | b | c | x ) ) break ;

    for ( i = 0; i < n; ++i )
    {
      scanf ( "%d", y + i );
    }

    for ( i = 0; i < n; ++i )
    {
      if ( i )
      {
        x = ( a * x + b ) % c;
        ++res;
      }
      for ( ; res <= TLE; ++res )
      {
        if ( x == y[ i ] ) break ;
        x = ( a * x + b ) % c;
      }
    }

    if ( res > TLE )
    {
      puts ( "-1" );
    }
    else
    {
      printf ( "%d\n", res );
    }
  }

  return ( 0 );
}