#include #include using namespace std; using lint=int64_t; int main() { lint L,R,M; cin >> L >> R >> M; if(M<=R-L+1) cout << M << endl; else { lint rL=L%M; lint rR=R%M; if(rR-rL>=0) cout << rR-rL+1 << endl; else cout << (M-rL+1)+rR << endl; } return 0; }