import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	long h = sc.nextLong();
    	sc.close();
    	System.out.println(cntUp(h));
    }

    static long cntUp(long h){
    	if(1 == h){
    		return 1L;
    	}
    	else{
    		return cntUp(h / 2) * 2 + 1;
    	}
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	long h = sc.nextLong();
    	sc.close();
    	System.out.println(cntUp(h));
    }

    static long cntUp(long h){
    	if(1 == h){
    		return 1L;
    	}
    	else{
    		return cntUp(h / 2) * 2 + 1;
    	}
    }
} Main public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	long h = sc.nextLong();
    	sc.close();
    	System.out.println(cntUp(h));
    } main {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	long h = sc.nextLong();
    	sc.close();
    	System.out.println(cntUp(h));
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long h = sc.nextLong(); h sc.nextLong() sc.nextLong sc sc.close() sc.close sc System.out.println(cntUp(h)) System.out.println System.out System System.out cntUp(h) cntUp h String[] args args static long cntUp(long h){
    	if(1 == h){
    		return 1L;
    	}
    	else{
    		return cntUp(h / 2) * 2 + 1;
    	}
    } cntUp {
    	if(1 == h){
    		return 1L;
    	}
    	else{
    		return cntUp(h / 2) * 2 + 1;
    	}
    } if(1 == h){
    		return 1L;
    	}
    	else{
    		return cntUp(h / 2) * 2 + 1;
    	} 1 == h 1 h {
    		return 1L;
    	} return 1L; 1L {
    		return cntUp(h / 2) * 2 + 1;
    	} return cntUp(h / 2) * 2 + 1; cntUp(h / 2) * 2 + 1 cntUp(h / 2) * 2 cntUp(h / 2) cntUp h / 2 h 2 2 1 long h h public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	long h = sc.nextLong();
    	sc.close();
    	System.out.println(cntUp(h));
    }

    static long cntUp(long h){
    	if(1 == h){
    		return 1L;
    	}
    	else{
    		return cntUp(h / 2) * 2 + 1;
    	}
    }
} public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	long h = sc.nextLong();
    	sc.close();
    	System.out.println(cntUp(h));
    }

    static long cntUp(long h){
    	if(1 == h){
    		return 1L;
    	}
    	else{
    		return cntUp(h / 2) * 2 + 1;
    	}
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	long h = sc.nextLong();
    	sc.close();
    	System.out.println(cntUp(h));
    }

    static long cntUp(long h){
    	if(1 == h){
    		return 1L;
    	}
    	else{
    		return cntUp(h / 2) * 2 + 1;
    	}
    }
}