import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final long H = Long.parseLong(sc.next());
        out.println(ans(H));
        
        out.flush();
    }
    
    static long ans(long x) {
        if (x == 1) return 1;
        return 2 * ans(x / 2) + 1;
    }
} import java.io.*; io.* java import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final long H = Long.parseLong(sc.next());
        out.println(ans(H));
        
        out.flush();
    }
    
    static long ans(long x) {
        if (x == 1) return 1;
        return 2 * ans(x / 2) + 1;
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final long H = Long.parseLong(sc.next());
        out.println(ans(H));
        
        out.flush();
    } main {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final long H = Long.parseLong(sc.next());
        out.println(ans(H));
        
        out.flush();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) final long H = Long.parseLong(sc.next()); H Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc out.println(ans(H)) out.println out ans(H) ans H out.flush() out.flush out String[] args args static long ans(long x) {
        if (x == 1) return 1;
        return 2 * ans(x / 2) + 1;
    } ans {
        if (x == 1) return 1;
        return 2 * ans(x / 2) + 1;
    } if (x == 1) return 1; x == 1 x 1 return 1; 1 return 2 * ans(x / 2) + 1; 2 * ans(x / 2) + 1 2 * ans(x / 2) 2 ans(x / 2) ans x / 2 x 2 1 long x x public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final long H = Long.parseLong(sc.next());
        out.println(ans(H));
        
        out.flush();
    }
    
    static long ans(long x) {
        if (x == 1) return 1;
        return 2 * ans(x / 2) + 1;
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final long H = Long.parseLong(sc.next());
        out.println(ans(H));
        
        out.flush();
    }
    
    static long ans(long x) {
        if (x == 1) return 1;
        return 2 * ans(x / 2) + 1;
    }
} Main
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final long H = Long.parseLong(sc.next());
        out.println(ans(H));
        
        out.flush();
    }
    
    static long ans(long x) {
        if (x == 1) return 1;
        return 2 * ans(x / 2) + 1;
    }
}