#include using namespace std; int main() { long long L, R, C; cin >> L >> R >> C; int ans = 1000; for( int i = L; i <= R; i++ ) { int a = i * C % 1000; if( a ) a = 1000 - a; ans = min( ans, a ); if( ans == 0 ) break; } cout << ans << endl; }