#include <stdio.h>
#include <stdlib.h>

#define N 100

int
main (
  int   argc,
  char *argv[ ]
  )
{
  int i, j;

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

    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", &y[ i ] );

    j = 0;
    for ( i = 0; i <= 10000; ++i )
    {
      if ( x == y[ j ] )
      {
        ++j;
        if ( j >= n ) break ;
      }

      x = ( x * a + b ) % c;
    }

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


  return ( EXIT_SUCCESS );
}