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