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

typedef long long ll;

#define f(n) for(int i = 0; i < n; i++)

int main () {
    int a, b, k, r, c;
    cin >> a >> b >> k;
    int p = 0;
    c = a;

    bool arr [b];

    f(b) {
        if (b % k != 0) {
            arr[i] = true;
            p++;
        }
    }

    f(b-a) {
        if (arr[c+2] == false && c + 2 < b) {
            r += 2;
            c += 3;
        } else if (c + 2 <= b) {
            r++;
            c += 2;
        }
    }

    if (c != b) {
        r++;
    }

    //r = ((b-a) /2 + (b-a) % 2) + t;

    cout << r;

    return 0;
}

