import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		long n = scn.nextLong();
		long ans;
      	long count;
      	ans=count=0;
      	while(n != 0){
          n/=2;
          ans += Math.pow(2, count);
          count++;
        }
      	System.out.println(ans);
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		long n = scn.nextLong();
		long ans;
      	long count;
      	ans=count=0;
      	while(n != 0){
          n/=2;
          ans += Math.pow(2, count);
          count++;
        }
      	System.out.println(ans);
	}
} Main public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		long n = scn.nextLong();
		long ans;
      	long count;
      	ans=count=0;
      	while(n != 0){
          n/=2;
          ans += Math.pow(2, count);
          count++;
        }
      	System.out.println(ans);
	} main {
		Scanner scn = new Scanner(System.in);
		long n = scn.nextLong();
		long ans;
      	long count;
      	ans=count=0;
      	while(n != 0){
          n/=2;
          ans += Math.pow(2, count);
          count++;
        }
      	System.out.println(ans);
	} Scanner scn = new Scanner(System.in); scn new Scanner(System.in) long n = scn.nextLong(); n scn.nextLong() scn.nextLong scn long ans; ans long count; count ans=count=0 ans count=0 count 0 while(n != 0){
          n/=2;
          ans += Math.pow(2, count);
          count++;
        } n != 0 n 0 {
          n/=2;
          ans += Math.pow(2, count);
          count++;
        } n/=2 n 2 ans += Math.pow(2, count) ans Math.pow(2, count) Math.pow Math 2 count count++ count System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		long n = scn.nextLong();
		long ans;
      	long count;
      	ans=count=0;
      	while(n != 0){
          n/=2;
          ans += Math.pow(2, count);
          count++;
        }
      	System.out.println(ans);
	}
} public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		long n = scn.nextLong();
		long ans;
      	long count;
      	ans=count=0;
      	while(n != 0){
          n/=2;
          ans += Math.pow(2, count);
          count++;
        }
      	System.out.println(ans);
	}
} Main
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		long n = scn.nextLong();
		long ans;
      	long count;
      	ans=count=0;
      	while(n != 0){
          n/=2;
          ans += Math.pow(2, count);
          count++;
        }
      	System.out.println(ans);
	}
}
