import std.stdio;
import std.algorithm;
import std.string;
import std.container;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}

void main() {
    long N, K; scanf("%d %d\n", &N, &K);
    long f(long n) {
        return n + 1 + (n / (K - 1));
    }
    long x = 0;
    for (long n = 1; n < N; n++) {
        x = f(x);
    }
    writeln(x);
}