import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		System.out.println(Main.count(N));
	}

	public static long count(long N) {
		if (N==0) {
			return 0;
		}
		return count(N/2)*2+1;
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		System.out.println(Main.count(N));
	}

	public static long count(long N) {
		if (N==0) {
			return 0;
		}
		return count(N/2)*2+1;
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		System.out.println(Main.count(N));
	} main {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		System.out.println(Main.count(N));
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long N = sc.nextLong(); N sc.nextLong() sc.nextLong sc System.out.println(Main.count(N)) System.out.println System.out System System.out Main.count(N) Main.count Main N String[] args args public static long count(long N) {
		if (N==0) {
			return 0;
		}
		return count(N/2)*2+1;
	} count {
		if (N==0) {
			return 0;
		}
		return count(N/2)*2+1;
	} if (N==0) {
			return 0;
		} N==0 N 0 {
			return 0;
		} return 0; 0 return count(N/2)*2+1; count(N/2)*2+1 count(N/2)*2 count(N/2) count N/2 N 2 2 1 long N N public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		System.out.println(Main.count(N));
	}

	public static long count(long N) {
		if (N==0) {
			return 0;
		}
		return count(N/2)*2+1;
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		System.out.println(Main.count(N));
	}

	public static long count(long N) {
		if (N==0) {
			return 0;
		}
		return count(N/2)*2+1;
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		System.out.println(Main.count(N));
	}

	public static long count(long N) {
		if (N==0) {
			return 0;
		}
		return count(N/2)*2+1;
	}
}