import java.util.*;
public class Main { 
    static Map<Long, Long> cache = new HashMap<>();
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long cnt = helper(n);
        System.out.println(cnt);
    }

    private static Long helper(long h) {
       if(cache.containsKey(h))
         return cache.get(h);
       if(h == 1) {
         	cache.put(h, 1L);
            return 1L;
       }
       long cnt = 2 * helper(h/2) + 1;
       cache.put(h, cnt);
       return cnt;
    }
} import java.util.*; util.* java public class Main { 
    static Map<Long, Long> cache = new HashMap<>();
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long cnt = helper(n);
        System.out.println(cnt);
    }

    private static Long helper(long h) {
       if(cache.containsKey(h))
         return cache.get(h);
       if(h == 1) {
         	cache.put(h, 1L);
            return 1L;
       }
       long cnt = 2 * helper(h/2) + 1;
       cache.put(h, cnt);
       return cnt;
    }
} Main static Map<Long, Long> cache = new HashMap<>(); cache new HashMap<>() public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long cnt = helper(n);
        System.out.println(cnt);
    } main {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long cnt = helper(n);
        System.out.println(cnt);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long n = sc.nextLong(); n sc.nextLong() sc.nextLong sc long cnt = helper(n); cnt helper(n) helper n System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args private static Long helper(long h) {
       if(cache.containsKey(h))
         return cache.get(h);
       if(h == 1) {
         	cache.put(h, 1L);
            return 1L;
       }
       long cnt = 2 * helper(h/2) + 1;
       cache.put(h, cnt);
       return cnt;
    } helper {
       if(cache.containsKey(h))
         return cache.get(h);
       if(h == 1) {
         	cache.put(h, 1L);
            return 1L;
       }
       long cnt = 2 * helper(h/2) + 1;
       cache.put(h, cnt);
       return cnt;
    } if(cache.containsKey(h))
         return cache.get(h); cache.containsKey(h) cache.containsKey cache h return cache.get(h); cache.get(h) cache.get cache h if(h == 1) {
         	cache.put(h, 1L);
            return 1L;
       } h == 1 h 1 {
         	cache.put(h, 1L);
            return 1L;
       } cache.put(h, 1L) cache.put cache h 1L return 1L; 1L long cnt = 2 * helper(h/2) + 1; cnt 2 * helper(h/2) + 1 2 * helper(h/2) 2 helper(h/2) helper h/2 h 2 1 cache.put(h, cnt) cache.put cache h cnt return cnt; cnt long h h public class Main { 
    static Map<Long, Long> cache = new HashMap<>();
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long cnt = helper(n);
        System.out.println(cnt);
    }

    private static Long helper(long h) {
       if(cache.containsKey(h))
         return cache.get(h);
       if(h == 1) {
         	cache.put(h, 1L);
            return 1L;
       }
       long cnt = 2 * helper(h/2) + 1;
       cache.put(h, cnt);
       return cnt;
    }
} public class Main { 
    static Map<Long, Long> cache = new HashMap<>();
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long cnt = helper(n);
        System.out.println(cnt);
    }

    private static Long helper(long h) {
       if(cache.containsKey(h))
         return cache.get(h);
       if(h == 1) {
         	cache.put(h, 1L);
            return 1L;
       }
       long cnt = 2 * helper(h/2) + 1;
       cache.put(h, cnt);
       return cnt;
    }
} Main
import java.util.*;
public class Main { 
    static Map<Long, Long> cache = new HashMap<>();
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long cnt = helper(n);
        System.out.println(cnt);
    }

    private static Long helper(long h) {
       if(cache.containsKey(h))
         return cache.get(h);
       if(h == 1) {
         	cache.put(h, 1L);
            return 1L;
       }
       long cnt = 2 * helper(h/2) + 1;
       cache.put(h, cnt);
       return cnt;
    }
}
