#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int l, r, c; cin >> l >> r >> c; int ans = 999; for (int i = l; i <= min(r, l + 1000); i++) { long long x = (long long) i * c; int y = 1000 - (x % 1000); y %= 1000; ans = min(ans, y); } cout << ans << '\n'; }