#include<bits/stdc++.h>
using namespace std;

#define endl "\n"

const long long MAX = 1e18;
//////SLOW

long long a, b, k, ost;
long long solve(long long i, long long steps){
    if(i != a && i%k == ost){
        return MAX;
    }
    if(i >= b){
        return steps;
    }
    return min(solve(i + 1, steps + 1), solve(i + 2, steps + 1));
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);


    cin>>a>>b>>k;
    ost = a % k - 1;
    if(ost == -1) ost = k - 1;
    cout<<solve(a, 0)<<endl;

}

