//package codeforces;

import java.util.Scanner;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.TreeMap;
import java.util.TreeSet;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Stack;
import java.util.Set;

public class Main {
	static Scanner scn = new Scanner(System.in);
	static int mod = 1000000007;
	static long count = 0;

	public static void main(String[] args) {
		long h=scn.nextLong();
		if(h==1)
		{
			System.out.println("1");
		}
		else
		{
			System.out.println(hel(h));
		}
		
	}
	public static long hel(long d)
	{	if(d<1)
		return 0;
		if(d==1)
			return 1;
		else
		{
			return 1+2*hel(Math.floorDiv(d, 2));
		}
	}
}

/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz