A,B=list(map(int,input().split())) for r in range(abs(B)): if (A-r)%B==0: print(r) exit(0)