#include<iostream>
using namespace std;
int main()
{
    int A,B,K,br=0;
    cin>>A>>B>>K;
    while (A!=B)
    {
        if ((A+1)==B)
        {
            A++;
            br++;
        }
        else if ((A+2)%K!=0)
        {
            A=A+2;
            br++;
        }
        else
        {
            A++;
            br++;
        }
    }
    cout<<br<<endl;
    return 0;
}
