h, a = map(int, input().split()) c = 0 while h > 0: c += 1 h //= a print((1 << c) - 1)