import java.util.*;

class Main{

    public static void main(String args[]) throws Exception{
        Main main = new Main();
    }

    public Main(){
        Scanner scanner = new Scanner(System.in);
        long H = scanner.nextLong();

        System.out.println(search(H));
    }

    public long search(long H){
        if(H == 1L) return 1L;

        return 2*search(H/2L) + 1L;
    }
} import java.util.*; util.* java class Main{

    public static void main(String args[]) throws Exception{
        Main main = new Main();
    }

    public Main(){
        Scanner scanner = new Scanner(System.in);
        long H = scanner.nextLong();

        System.out.println(search(H));
    }

    public long search(long H){
        if(H == 1L) return 1L;

        return 2*search(H/2L) + 1L;
    }
} Main public static void main(String args[]) throws Exception{
        Main main = new Main();
    } main {
        Main main = new Main();
    } Main main = new Main(); main new Main() String args[] args public Main(){
        Scanner scanner = new Scanner(System.in);
        long H = scanner.nextLong();

        System.out.println(search(H));
    } Main {
        Scanner scanner = new Scanner(System.in);
        long H = scanner.nextLong();

        System.out.println(search(H));
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) long H = scanner.nextLong(); H scanner.nextLong() scanner.nextLong scanner System.out.println(search(H)) System.out.println System.out System System.out search(H) search H public long search(long H){
        if(H == 1L) return 1L;

        return 2*search(H/2L) + 1L;
    } search {
        if(H == 1L) return 1L;

        return 2*search(H/2L) + 1L;
    } if(H == 1L) return 1L; H == 1L H 1L return 1L; 1L return 2*search(H/2L) + 1L; 2*search(H/2L) + 1L 2*search(H/2L) 2 search(H/2L) search H/2L H 2L 1L long H H
import java.util.*;

class Main{

    public static void main(String args[]) throws Exception{
        Main main = new Main();
    }

    public Main(){
        Scanner scanner = new Scanner(System.in);
        long H = scanner.nextLong();

        System.out.println(search(H));
    }

    public long search(long H){
        if(H == 1L) return 1L;

        return 2*search(H/2L) + 1L;
    }
}
