#include #define int long long using namespace std; int l, r, c; signed main() { int i; cin >> l >> r >> c; int ans = 999; for (i = l; i <= min(r, l + 1000); i++) { int score = (1000 - c * i % 1000) % 1000; ans = min(ans, score); } cout << ans << endl; return 0; }