#include<iostream>
//#include<>
//#include<>

#define endl '\n'

using namespace std;

//long int memo[]

void budi_burz(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

}

long long rec(long long a, long long b, long long k, long long tek){
    if(a % k == 0) return 10000000000;
    if( a < b) return 10000000000;
    if(a == b) return tek;
    int ans = min(rec(a - 1, b, k, tek + 1), rec(a - 2, b, k, tek + 1));
    return ans;
}

int main(){

    budi_burz();
    long long a, b, k;
    cin >> a >> b >> k;
    cout << rec(b, a, k, 0) << endl;

    return 0;
}