#include using namespace std; typedef long long ll; int main() { ll l, r, c; cin >> l >> r >> c; ll min_change = 999; for(ll x = l; x <= r; x++){ ll change = 1000-x*c%1000; if(change == 1000)change =0; if(min_change > change){ min_change = change; } } cout << min_change << endl; return 0; }