#include using namespace std; int main() { long long l, r, c; cin >> l >> r >> c; long long ans = 1000; for (long long x = l; x <= min(l + 1000, r); x++) { long long now = (x * c) % 1000; if (now != 0) now = 1000 - now; ans = min(ans, now); } cout << ans << endl; return 0; }