import sys input=lambda:sys.stdin.readline().rstrip() N,M=[int(input()) for i in range(2)] A=[2,5] for i in range(2): while M%A[i]==0: M//=A[i] N*=A[1-i] while N%10==0: N//=10 print((N//M)%10 if N%M==0 else -1)