import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        System.out.println(mon(n));
        sc.close();
    }
    public static long mon(long a){
        if(a == 1) return 1;
        return 2 * mon(a / 2) + 1;
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        System.out.println(mon(n));
        sc.close();
    }
    public static long mon(long a){
        if(a == 1) return 1;
        return 2 * mon(a / 2) + 1;
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        System.out.println(mon(n));
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        System.out.println(mon(n));
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long n = sc.nextLong(); n sc.nextLong() sc.nextLong sc System.out.println(mon(n)) System.out.println System.out System System.out mon(n) mon n sc.close() sc.close sc String[] args args public static long mon(long a){
        if(a == 1) return 1;
        return 2 * mon(a / 2) + 1;
    } mon {
        if(a == 1) return 1;
        return 2 * mon(a / 2) + 1;
    } if(a == 1) return 1; a == 1 a 1 return 1; 1 return 2 * mon(a / 2) + 1; 2 * mon(a / 2) + 1 2 * mon(a / 2) 2 mon(a / 2) mon a / 2 a 2 1 long a a public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        System.out.println(mon(n));
        sc.close();
    }
    public static long mon(long a){
        if(a == 1) return 1;
        return 2 * mon(a / 2) + 1;
    }
} public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        System.out.println(mon(n));
        sc.close();
    }
    public static long mon(long a){
        if(a == 1) return 1;
        return 2 * mon(a / 2) + 1;
    }
} Main
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        System.out.println(mon(n));
        sc.close();
    }
    public static long mon(long a){
        if(a == 1) return 1;
        return 2 * mon(a / 2) + 1;
    }
}