import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		long n = scn.nextLong();
		long ans=0;
		long i=1;
		while(n>0) {
			n/=2;
			ans+=i;
			i*=2;
		}System.out.println(ans);
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		long n = scn.nextLong();
		long ans=0;
		long i=1;
		while(n>0) {
			n/=2;
			ans+=i;
			i*=2;
		}System.out.println(ans);
	}
} Main public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		long n = scn.nextLong();
		long ans=0;
		long i=1;
		while(n>0) {
			n/=2;
			ans+=i;
			i*=2;
		}System.out.println(ans);
	} main {
		Scanner scn = new Scanner(System.in);
		long n = scn.nextLong();
		long ans=0;
		long i=1;
		while(n>0) {
			n/=2;
			ans+=i;
			i*=2;
		}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=0; ans 0 long i=1; i 1 while(n>0) {
			n/=2;
			ans+=i;
			i*=2;
		} n>0 n 0 {
			n/=2;
			ans+=i;
			i*=2;
		} n/=2 n 2 ans+=i ans i i*=2 i 2 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) {
		Scanner scn = new Scanner(System.in);
		long n = scn.nextLong();
		long ans=0;
		long i=1;
		while(n>0) {
			n/=2;
			ans+=i;
			i*=2;
		}System.out.println(ans);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		long n = scn.nextLong();
		long ans=0;
		long i=1;
		while(n>0) {
			n/=2;
			ans+=i;
			i*=2;
		}System.out.println(ans);
	}
} Main
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		long n = scn.nextLong();
		long ans=0;
		long i=1;
		while(n>0) {
			n/=2;
			ans+=i;
			i*=2;
		}System.out.println(ans);
	}
}