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