//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));
		}
	}
} import java.util.Scanner; Scanner java.util import java.util.HashMap; HashMap java.util import java.util.HashSet; HashSet java.util import java.util.LinkedList; LinkedList java.util import java.util.TreeMap; TreeMap java.util import java.util.TreeSet; TreeSet java.util import java.math.BigInteger; BigInteger java.math import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.Collections; Collections java.util import java.util.Stack; Stack java.util import java.util.Set; Set java.util 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));
		}
	}
} Main static Scanner scn = new Scanner(System.in); scn new Scanner(System.in) static int mod = 1000000007; mod 1000000007 static long count = 0; 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));
		}
		
	} main {
		long h=scn.nextLong();
		if(h==1)
		{
			System.out.println("1");
		}
		else
		{
			System.out.println(hel(h));
		}
		
	} long h=scn.nextLong(); h scn.nextLong() scn.nextLong scn if(h==1)
		{
			System.out.println("1");
		}
		else
		{
			System.out.println(hel(h));
		} h==1 h 1 {
			System.out.println("1");
		} System.out.println("1") System.out.println System.out System System.out "1" {
			System.out.println(hel(h));
		} System.out.println(hel(h)) System.out.println System.out System System.out hel(h) hel h String[] args args 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));
		}
	} hel {	if(d<1)
		return 0;
		if(d==1)
			return 1;
		else
		{
			return 1+2*hel(Math.floorDiv(d, 2));
		}
	} if(d<1)
		return 0; d<1 d 1 return 0; 0 if(d==1)
			return 1;
		else
		{
			return 1+2*hel(Math.floorDiv(d, 2));
		} d==1 d 1 return 1; 1 {
			return 1+2*hel(Math.floorDiv(d, 2));
		} return 1+2*hel(Math.floorDiv(d, 2)); 1+2*hel(Math.floorDiv(d, 2)) 1 2*hel(Math.floorDiv(d, 2)) 2 hel(Math.floorDiv(d, 2)) hel Math.floorDiv(d, 2) Math.floorDiv Math d 2 long d d 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));
		}
	}
} 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));
		}
	}
} Main
//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));
		}
	}
}
