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