#include using namespace std; using lint = long long; #define rep(i, s, n) for (int i = (s); i < (int)(n); i++) #define Yes cout << "Yes" << endl #define No cout << "No" << endl int main() { lint l,r,c,b,ans=999; cin >> l >> r >> c; rep(i,l,r+1) { if((i*c)%1000==0) { ans=0; } else { b = 1000 - ((i*c)%1000); ans=min(ans,b); } } cout << ans << endl; }