n=input() m=input() o=n%m b=n/m for i in range(114514): if o==0: print b break o*=10 b=o/m o=o%m else: print -1