#include <bits/stdc++.h>

using namespace std;

template <typename T>
T intpow(T x, T n){
    T ret = 1;
    while(n > 0) {
        if(n & 1) (ret *= x);
        (x *= x);
        n >>= 1;
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    long long h, a; cin >> h >> a;
    long long m = 0;
    while(h > 0){
        h /= a;
        m++;
    }
    cout << intpow(2LL, m) - 1 << endl;
}