#include <bits/stdc++.h>

using namespace std;

int const PMAX = 10000;
int const NMAX = 10000;
int A, B;
int N, P;
int colors[1 + NMAX];
int moves[1 + PMAX];

int bfs() {
    queue<int> q;
    q.push(A);
    while(true) {
        int from = q.front();
        q.pop();
        if(from == B) {
            return moves[from];
        }
        for(int i = 1; i <= N; i++) {
            int to = (from * colors[i]) % P;
            if(moves[to] == 0 && to != A) {
                moves[to] = moves[from] + 1;
                q.push(to);
            }
        }
    }
}

int main() {
    cin >> A >> B;
    cin >> N >> P;
    for(int i = 1; i <= N; i++) {
        cin >> colors[i];
    }
    cout << bfs();
}