#include <iostream>
#include <vector>
#include <utility>
#include <memory>
#include <algorithm>
#include <cmath>
#include <functional>

using namespace std;


int main() {
	int n, k;
	cin >> n >> k;

	auto mapping = [k](size_t i) {
		return i + i / (k - 1) + 1;
	};

	size_t v = 0;
	for (int i = 0; i < n - 1; i++) {
		v = mapping(v);
	}
	cout << v << endl;
}