import java.util.*;
import java.io.*;

public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();   
        int res = 0;
        for (int i = 0; i <= 50; i++) {
            if (h >= Math.pow(2, i) && h < Math.pow(2, i+1)) {
                res = i;
                break;
            }
        }
        long sum = 0;
        for (int i = 0; i <= res; i++) {
            sum += Math.pow(2, i);
        }
        System.out.println(sum);
    }
} import java.util.*; util.* java import java.io.*; io.* java public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();   
        int res = 0;
        for (int i = 0; i <= 50; i++) {
            if (h >= Math.pow(2, i) && h < Math.pow(2, i+1)) {
                res = i;
                break;
            }
        }
        long sum = 0;
        for (int i = 0; i <= res; i++) {
            sum += Math.pow(2, i);
        }
        System.out.println(sum);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();   
        int res = 0;
        for (int i = 0; i <= 50; i++) {
            if (h >= Math.pow(2, i) && h < Math.pow(2, i+1)) {
                res = i;
                break;
            }
        }
        long sum = 0;
        for (int i = 0; i <= res; i++) {
            sum += Math.pow(2, i);
        }
        System.out.println(sum);
    } main {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();   
        int res = 0;
        for (int i = 0; i <= 50; i++) {
            if (h >= Math.pow(2, i) && h < Math.pow(2, i+1)) {
                res = i;
                break;
            }
        }
        long sum = 0;
        for (int i = 0; i <= res; i++) {
            sum += Math.pow(2, i);
        }
        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 int res = 0; res 0 for (int i = 0; i <= 50; i++) {
            if (h >= Math.pow(2, i) && h < Math.pow(2, i+1)) {
                res = i;
                break;
            }
        } int i = 0; int i = 0; i 0 i <= 50 i 50 i++ i++ i {
            if (h >= Math.pow(2, i) && h < Math.pow(2, i+1)) {
                res = i;
                break;
            }
        } {
            if (h >= Math.pow(2, i) && h < Math.pow(2, i+1)) {
                res = i;
                break;
            }
        } if (h >= Math.pow(2, i) && h < Math.pow(2, i+1)) {
                res = i;
                break;
            } h >= Math.pow(2, i) && h < Math.pow(2, i+1) h >= Math.pow(2, i) h Math.pow(2, i) Math.pow Math 2 i h < Math.pow(2, i+1) h Math.pow(2, i+1) Math.pow Math 2 i+1 i 1 {
                res = i;
                break;
            } res = i res i break; long sum = 0; sum 0 for (int i = 0; i <= res; i++) {
            sum += Math.pow(2, i);
        } int i = 0; int i = 0; i 0 i <= res i res i++ i++ i {
            sum += Math.pow(2, i);
        } {
            sum += Math.pow(2, i);
        } sum += Math.pow(2, i) sum Math.pow(2, i) Math.pow Math 2 i 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) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();   
        int res = 0;
        for (int i = 0; i <= 50; i++) {
            if (h >= Math.pow(2, i) && h < Math.pow(2, i+1)) {
                res = i;
                break;
            }
        }
        long sum = 0;
        for (int i = 0; i <= res; i++) {
            sum += Math.pow(2, i);
        }
        System.out.println(sum);
    }
} public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();   
        int res = 0;
        for (int i = 0; i <= 50; i++) {
            if (h >= Math.pow(2, i) && h < Math.pow(2, i+1)) {
                res = i;
                break;
            }
        }
        long sum = 0;
        for (int i = 0; i <= res; i++) {
            sum += Math.pow(2, i);
        }
        System.out.println(sum);
    }
} Main
import java.util.*;
import java.io.*;

public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();   
        int res = 0;
        for (int i = 0; i <= 50; i++) {
            if (h >= Math.pow(2, i) && h < Math.pow(2, i+1)) {
                res = i;
                break;
            }
        }
        long sum = 0;
        for (int i = 0; i <= res; i++) {
            sum += Math.pow(2, i);
        }
        System.out.println(sum);
    }
}