#include using namespace std; #define overload4(_1, _2, _3, _4, name, ...) name #define rep1(n) for(int i = 0; i < (int)(n); ++i) #define rep2(i, n) for(int i = 0; i < (int)(n); ++i) #define rep3(i, a, b) for(int i = (a); i < (int)(b); ++i) #define rep4(i, a, b, c) for(int i = (a); i < (int)(b); i += (c)) #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) using ll = long long; using ull = unsigned long long; using ld = long double; using u16 = uint16_t; int main(){ ull H, A; cin >> H >> A; ull n = 0; while(H > 0){ H /= A; ++n; } ull ans = 0; ull i = 1; while(n > 0){ ans += i; i *= 2; --n; } cout << ans << endl; }