#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; #define REP(i,n) for(int i=0;i<int(n);i++) int main(void){ cin.tie(nullptr); ios_base::sync_with_stdio(false); int i,j,k; int L,R,C; cin >> L >> R >> C; int x=1000/C; if(L<=x && x<=R) cout << 1000-C*x << endl; else if(R<x) cout << 1000-C*R << endl; else cout << 1000 << endl; return 0; }