import sys input = lambda: sys.stdin.readline().rstrip() def main(): # 入力 H, A = map(int, input().split()) # 計算・出力 ans = 0 while H: H //= A ans += 1 print(2**ans-1) if __name__ == "__main__": main()