#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

//typedef pair<long long int, long long int> P;
long long int INF = 1e18;

long long int N, K;

bool check(long long int A){
	long long int hoge = A;
	for(int i = 0; i < N - 1; i++){
		hoge -= hoge / K + (hoge % K > 0);
	}
	return (hoge > 0);
}

long long int bin_search(long long int lef, long long int rig){
	long long int middle = (lef + rig) / 2;
	//cout << middle << " ";
	if(rig - lef <= 1){
		if(check(lef)){
			return lef;
		}else{
			return rig;
		}
	}
	if(check(middle)){
		rig = middle;
	}else{
		lef = middle;
	}
	return bin_search(lef, rig);
}

int main(){
	
	cin >> N >> K;
	
	cout << bin_search(0, 1e18 + 1) - 1 << endl;
	
	return 0;
}
