from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N = int(input()) M = int(input()) X = Counter([]) Y = Counter([]) while N%5==0: N//=5 X[5] += 1 while N%2==0: N//=2 X[2] += 1 while M%5==0: M//=5 Y[5] += 1 while M%2==0: M//=2 Y[2] += 1 if M!=1: print(-1) exit() m = min(X[2],X[5]) X[2] -= m X[5] -= m m = min(Y[2],Y[5]) Y[2] -= m Y[5] -= m m = min(X[2],Y[2]) X[2] -= m Y[2] -= m m = min(X[5],Y[5]) X[5] -= m Y[5] -= m K = max(Y.values()) X[5] += K - Y[5] X[2] += K - Y[2] N *= pow(5,X[5])*pow(2,X[2]) S = str(N) for s in S[::-1]: if s!='0': print(s) exit()