h, a = map(int, input().split()) cnt = 0 while h: h //= a cnt += 1 ans = pow(2, cnt) - 1 print(ans)