import java.util.*;


class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        Long H = sc.nextLong();
        int count = 0;
        Long ans = 0L;
        while (H>0) {
            H = H/2;
            ans += (long) Math.pow(2, count++);
        }
        System.out.println(ans);
    }
} import java.util.*; util.* java class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        Long H = sc.nextLong();
        int count = 0;
        Long ans = 0L;
        while (H>0) {
            H = H/2;
            ans += (long) Math.pow(2, count++);
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        Long H = sc.nextLong();
        int count = 0;
        Long ans = 0L;
        while (H>0) {
            H = H/2;
            ans += (long) Math.pow(2, count++);
        }
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        
        Long H = sc.nextLong();
        int count = 0;
        Long ans = 0L;
        while (H>0) {
            H = H/2;
            ans += (long) Math.pow(2, count++);
        }
        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Long H = sc.nextLong(); H sc.nextLong() sc.nextLong sc int count = 0; count 0 Long ans = 0L; ans 0L while (H>0) {
            H = H/2;
            ans += (long) Math.pow(2, count++);
        } H>0 H 0 {
            H = H/2;
            ans += (long) Math.pow(2, count++);
        } H = H/2 H H/2 H 2 ans += (long) Math.pow(2, count++) ans (long) Math.pow(2, count++) Math.pow Math 2 count++ count System.out.println(ans) System.out.println System.out System System.out ans String[] args args
import java.util.*;


class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        Long H = sc.nextLong();
        int count = 0;
        Long ans = 0L;
        while (H>0) {
            H = H/2;
            ans += (long) Math.pow(2, count++);
        }
        System.out.println(ans);
    }
}