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