import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long monsters = 1;
        long sum = 0;
        while(H > 0){
            H /= 2;
            sum += monsters;
            monsters *= 2;
        }
        
        System.out.println(sum);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long monsters = 1;
        long sum = 0;
        while(H > 0){
            H /= 2;
            sum += monsters;
            monsters *= 2;
        }
        
        System.out.println(sum);
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long monsters = 1;
        long sum = 0;
        while(H > 0){
            H /= 2;
            sum += monsters;
            monsters *= 2;
        }
        
        System.out.println(sum);
    } main {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long monsters = 1;
        long sum = 0;
        while(H > 0){
            H /= 2;
            sum += monsters;
            monsters *= 2;
        }
        
        System.out.println(sum);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long H = sc.nextLong(); H sc.nextLong() sc.nextLong sc long monsters = 1; monsters 1 long sum = 0; sum 0 while(H > 0){
            H /= 2;
            sum += monsters;
            monsters *= 2;
        } H > 0 H 0 {
            H /= 2;
            sum += monsters;
            monsters *= 2;
        } H /= 2 H 2 sum += monsters sum monsters monsters *= 2 monsters 2 System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long monsters = 1;
        long sum = 0;
        while(H > 0){
            H /= 2;
            sum += monsters;
            monsters *= 2;
        }
        
        System.out.println(sum);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long monsters = 1;
        long sum = 0;
        while(H > 0){
            H /= 2;
            sum += monsters;
            monsters *= 2;
        }
        
        System.out.println(sum);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long monsters = 1;
        long sum = 0;
        while(H > 0){
            H /= 2;
            sum += monsters;
            monsters *= 2;
        }
        
        System.out.println(sum);
    }
}