H = int(eval(input()))

if H == 1:

    print((1))

else:

    cnt = 0

    while H > 3:

        H = H//2

        cnt += 1

    ans = 0

    for i in range(cnt):

        ans += 2**i

    print((int(((2**cnt)*3)+ans)))
H = int(eval(input()))





def f(H):

    if H == 1:

        return 1

    else:

        return f(H//2) * 2 + 1



print((f(H)))

H = int(eval(input()))
if H == 1:
    print((1))
else:
    cnt = 0
    while H > 3:
        H = H // 2
        cnt += 1
    ans = 0
    for i in range(cnt):
        ans += 2**i
    print((int(((2**cnt) * 3) + ans)))

H = int(eval(input()))


def f(H):
    if H == 1:
        return 1
    else:
        return f(H // 2) * 2 + 1


print((f(H)))

-if H == 1: -    print((1)) -else: -    cnt = 0 -    while H > 3: -        H = H // 2 -        cnt += 1 -    ans = 0 -    for i in range(cnt): -        ans += 2**i -    print((int(((2**cnt) * 3) + ans))) + + +def f(H): +    if H == 1: +        return 1 +    else: +        return f(H // 2) * 2 + 1 + + +print((f(H)))