#include using namespace std; void fast_io() { ios::sync_with_stdio(false); std::cin.tie(nullptr); } int main() { fast_io(); int l, r, c; cin >> l >> r >> c; vector vis(1000, false); for (long long x = l; x <= r; x++) { long long ch = 1000 - (x * c) % 1000; if (ch == 1000) ch = 0; if (vis[ch]) { break; } vis[ch] = true; } for (int i = 0; i < 1000; i++) { if (vis[i]) { cout << i << endl; return 0; } } }