from math import log, ceil h, a = map(int, input().split()) cnt = ceil(log(h, a)) ans = pow(2, cnt) - 1 print(ans)