#include using namespace std; long long powll(long long x, long long n) { long long ret = 1; while (n > 0) { if (n & 1) ret *= x; x *= x; n >>= 1; } return ret; } int main() { long long h, a; cin >> h >> a; long long count = 0; while (h > 0) { count++; h /= a; } cout << powll(2LL, count) - 1 << '\n'; return 0; }