l,r,c=map(int,input().split()) print(min((c*x)%1000 for x in range(l,min(l+1000,r)+1)))