import math h, a = map(int, input().split()) ans = 0 base = 1 while h >= 1: h = h // a ans += base base *= 2 print(int(ans))