
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <string>

using namespace std;

typedef long long ll;

const ll NMAX = ll(10e18) + 1;

int solve();

ll getNextGrad(const ll k, const ll a);

ll binarySearch(const ll k, const ll target);

ll jsearch(const ll k, const ll low, const ll high, const ll target);

int main(void) {
	while (solve()) {}
	return 0;
}

int solve() {

	ll N, k;
	cin >> N >> k;

	ll next = 1;

	//	コーナーケース
	{
		if (N == 1)
		{
			next = 0;
		}
		else if (N == 2)
		{
			next = 1;
		}
	}
	for (int i = 0; i < N - 2; i++)
	{
		const ll m = binarySearch(k, next - 1);
		const ll M = binarySearch(k, next + 1);
		next = jsearch(k, m, M, next);
	}

	cout << next << endl;


	return 0;
}

ll binarySearch(const ll k, const ll target)
{
	ll low = 0,
		high = NMAX,
		mid = (low+high)/2;

	while (getNextGrad(k,mid) != target)
	{
		mid = (low + high) / 2;

		if (getNextGrad(k, mid) > target)
		{
			high = mid;
		}
		else
		{
			low = mid;
		}

	}

	return mid;
}

ll jsearch(const ll k, const ll low, const ll high, const ll target)
{
	for (ll i = low; i <= high; i++)
	{
		if (getNextGrad(k, i) != target) { continue; }
		if (i % k == 0) { continue; }
		return i;
	}
	return -114514;
}

ll getNextGrad(const ll k, const ll a)
{
	return (a - (a / k + 1));
}

