#include #include using namespace std; using namespace atcoder; using i64 = long long int; int main() { i64 h, a; cin >> h >> a; int phase = 0; while (h >= 1) { h /= a; phase++; } cout << ((1LL << phase) - 1) << "\n"; return 0; }