#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
#define int long long
#define MOD 1e9+7
typedef pair<int,int> P;
typedef pair<int,P> PP;

signed main(){
  int n,k;
  cin>>n>>k;
  int ans=0;
  for(int i=1;i<n;i++){
    ans+=ans/(k-1)+1;
  }
  cout<<ans<<endl;
  return 0;
}

