#include "bits/stdc++.h"

using namespace std;

typedef long long ll;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll res = 0, n, k;
	cin >> n >> k;
	for (int i = 0; i < n - 1; i++) {
		res = (res / (k - 1)) + 1 + res;
	}
	cout << res << endl;
}