def main(): h, a = map(int, input().split()) c = 0 while h > 0: h //= a c += 1 print(2**c-1) if __name__ == '__main__': main()