import random P, Q, x , y = map(int, input().split()) def reverse(x): return int(str(x)[::-1]) while True: k = random.randint(0, 10 ** 100) rev_N = k * Q + y if rev_N % 10 == 0: continue N = reverse(rev_N) if N % P == x: print(N) break