import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        long hp = scan.nextLong();
        scan.close();
        long count = 2;
        int jyosu = 0; //hpは2の何乗か?

        if(hp == 1) System.out.println(count - 1);
        else{
            while(hp != 1){
                hp = hp / 2;
                jyosu++;
            }

            for(int i = 0;i < jyosu;i++) count = count * 2;
            System.out.println(count - 1);
        }
        /*
        ArrayList<Integer> h = new ArrayList<Integer>();
        h.add(scan.nextInt());
        int count = 0;
        scan.close();

        while(!h.isEmpty()){
            int hp = h.get(0);
            h.remove(0);
            if(hp != 1){
                hp = hp / 2;
                h.add(hp);
                h.add(hp);
            }
            count++;
        }
        System.out.println(count);
        */
    }


} import java.util.*; util.* java class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        long hp = scan.nextLong();
        scan.close();
        long count = 2;
        int jyosu = 0; //hpは2の何乗か?

        if(hp == 1) System.out.println(count - 1);
        else{
            while(hp != 1){
                hp = hp / 2;
                jyosu++;
            }

            for(int i = 0;i < jyosu;i++) count = count * 2;
            System.out.println(count - 1);
        }
        /*
        ArrayList<Integer> h = new ArrayList<Integer>();
        h.add(scan.nextInt());
        int count = 0;
        scan.close();

        while(!h.isEmpty()){
            int hp = h.get(0);
            h.remove(0);
            if(hp != 1){
                hp = hp / 2;
                h.add(hp);
                h.add(hp);
            }
            count++;
        }
        System.out.println(count);
        */
    }


} Main public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        long hp = scan.nextLong();
        scan.close();
        long count = 2;
        int jyosu = 0; //hpは2の何乗か?

        if(hp == 1) System.out.println(count - 1);
        else{
            while(hp != 1){
                hp = hp / 2;
                jyosu++;
            }

            for(int i = 0;i < jyosu;i++) count = count * 2;
            System.out.println(count - 1);
        }
        /*
        ArrayList<Integer> h = new ArrayList<Integer>();
        h.add(scan.nextInt());
        int count = 0;
        scan.close();

        while(!h.isEmpty()){
            int hp = h.get(0);
            h.remove(0);
            if(hp != 1){
                hp = hp / 2;
                h.add(hp);
                h.add(hp);
            }
            count++;
        }
        System.out.println(count);
        */
    } main {
        Scanner scan = new Scanner(System.in);
        long hp = scan.nextLong();
        scan.close();
        long count = 2;
        int jyosu = 0; //hpは2の何乗か?

        if(hp == 1) System.out.println(count - 1);
        else{
            while(hp != 1){
                hp = hp / 2;
                jyosu++;
            }

            for(int i = 0;i < jyosu;i++) count = count * 2;
            System.out.println(count - 1);
        }
        /*
        ArrayList<Integer> h = new ArrayList<Integer>();
        h.add(scan.nextInt());
        int count = 0;
        scan.close();

        while(!h.isEmpty()){
            int hp = h.get(0);
            h.remove(0);
            if(hp != 1){
                hp = hp / 2;
                h.add(hp);
                h.add(hp);
            }
            count++;
        }
        System.out.println(count);
        */
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) long hp = scan.nextLong(); hp scan.nextLong() scan.nextLong scan scan.close() scan.close scan long count = 2; count 2 int jyosu = 0; jyosu 0 if(hp == 1) System.out.println(count - 1);
        else{
            while(hp != 1){
                hp = hp / 2;
                jyosu++;
            }

            for(int i = 0;i < jyosu;i++) count = count * 2;
            System.out.println(count - 1);
        } hp == 1 hp 1 System.out.println(count - 1) System.out.println System.out System System.out count - 1 count 1 {
            while(hp != 1){
                hp = hp / 2;
                jyosu++;
            }

            for(int i = 0;i < jyosu;i++) count = count * 2;
            System.out.println(count - 1);
        } while(hp != 1){
                hp = hp / 2;
                jyosu++;
            } hp != 1 hp 1 {
                hp = hp / 2;
                jyosu++;
            } hp = hp / 2 hp hp / 2 hp 2 jyosu++ jyosu for(int i = 0;i < jyosu;i++) count = count * 2; int i = 0; int i = 0; i 0 i < jyosu i jyosu i++ i++ i count = count * 2; count = count * 2 count count * 2 count 2 System.out.println(count - 1) System.out.println System.out System System.out count - 1 count 1 String[] args args
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        long hp = scan.nextLong();
        scan.close();
        long count = 2;
        int jyosu = 0; //hpは2の何乗か?

        if(hp == 1) System.out.println(count - 1);
        else{
            while(hp != 1){
                hp = hp / 2;
                jyosu++;
            }

            for(int i = 0;i < jyosu;i++) count = count * 2;
            System.out.println(count - 1);
        }
        /*
        ArrayList<Integer> h = new ArrayList<Integer>();
        h.add(scan.nextInt());
        int count = 0;
        scan.close();

        while(!h.isEmpty()){
            int hp = h.get(0);
            h.remove(0);
            if(hp != 1){
                hp = hp / 2;
                h.add(hp);
                h.add(hp);
            }
            count++;
        }
        System.out.println(count);
        */
    }


}