#include<iostream>
using namespace std;
long long a, b, k;
long long where, steps = 0;
int main(){
    cin>>a>>b>>k;
    where = a;
    while(where!=b){
        if((where+2)%k==0 || where+1==b){
            where++;
        }else{
            where+=2;
        }
        steps++;
    }
    cout<<steps;
    return 0;
}
