H = int(eval(input()))



memo_count = {}

def searchCount(h):

    if h==1: # 脱出条件

        return 1

    elif h in memo_count:

        return memo_count[h]

    else:

        h_half = int(h / 2)

        memo_count[h] = 1 + 2*searchCount(h_half)

        return memo_count[h]



print((searchCount(H)))

# Problem D - Caracal vs Monster



# input

H = int(eval(input()))



# initialization

attack_dic = {}



# calc

def calc_count(h, attack):



    if h in attack_dic:

        return attack_dic[h]



    h = h // 2

    if h>0:

        attack += calc_count(h, attack) * 2 + 1

        attack_dic[h] = attack

        return attack

    else:

        return 1

ans = calc_count(H, 0)



# output

print(ans)

H = int(eval(input()))
memo_count = {}


def searchCount(h):
    if h == 1:  # 脱出条件
        return 1
    elif h in memo_count:
        return memo_count[h]
    else:
        h_half = int(h / 2)
        memo_count[h] = 1 + 2 * searchCount(h_half)
        return memo_count[h]


print((searchCount(H)))

# Problem D - Caracal vs Monster
# input
H = int(eval(input()))
# initialization
attack_dic = {}
# calc
def calc_count(h, attack):
    if h in attack_dic:
        return attack_dic[h]
    h = h // 2
    if h > 0:
        attack += calc_count(h, attack) * 2 + 1
        attack_dic[h] = attack
        return attack
    else:
        return 1


ans = calc_count(H, 0)
# output
print(ans)

+# Problem D - Caracal vs Monster +# input -memo_count = {} +# initialization +attack_dic = {} +# calc +def calc_count(h, attack): +    if h in attack_dic: +        return attack_dic[h] +    h = h // 2 +    if h > 0: +        attack += calc_count(h, attack) * 2 + 1 +        attack_dic[h] = attack +        return attack +    else: +        return 1 -def searchCount(h): -    if h == 1:  # 脱出条件 -        return 1 -    elif h in memo_count: -        return memo_count[h] -    else: -        h_half = int(h / 2) -        memo_count[h] = 1 + 2 * searchCount(h_half) -        return memo_count[h] - - -print((searchCount(H))) +ans = calc_count(H, 0) +# output +print(ans)