#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k;

bool check(ll x){
  ll cnt=0;
  while(x/k)x=x-(x+k-1)/k,cnt++;
  cnt+=x;
  return cnt >= n;
}

ll search(){
  if( n <= k) return n-1;

  ll L = n,M,R = (1e18)+10;
  while(L<R){
    M = (L+R)/2;
    if(check(M)) R = M;
    else L = M+1;
  }
  return L - 1;
}

int main(){
  cin>>n>>k;
  cout<<search()<<endl;
  return 0;
}