import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long hp = scanner.nextLong();
        scanner.close();

        long sumAttack = 0;
        long nextHp = hp;
        long numMon = 1;
        while(true) {
            if(nextHp != 1) {
                sumAttack += numMon;
                nextHp = nextHp / 2;
                numMon = numMon * 2;
            } else {
                sumAttack += numMon;
                break;
            }
        }

        System.out.println(sumAttack);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long hp = scanner.nextLong();
        scanner.close();

        long sumAttack = 0;
        long nextHp = hp;
        long numMon = 1;
        while(true) {
            if(nextHp != 1) {
                sumAttack += numMon;
                nextHp = nextHp / 2;
                numMon = numMon * 2;
            } else {
                sumAttack += numMon;
                break;
            }
        }

        System.out.println(sumAttack);
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long hp = scanner.nextLong();
        scanner.close();

        long sumAttack = 0;
        long nextHp = hp;
        long numMon = 1;
        while(true) {
            if(nextHp != 1) {
                sumAttack += numMon;
                nextHp = nextHp / 2;
                numMon = numMon * 2;
            } else {
                sumAttack += numMon;
                break;
            }
        }

        System.out.println(sumAttack);
    } main {
        Scanner scanner = new Scanner(System.in);
        long hp = scanner.nextLong();
        scanner.close();

        long sumAttack = 0;
        long nextHp = hp;
        long numMon = 1;
        while(true) {
            if(nextHp != 1) {
                sumAttack += numMon;
                nextHp = nextHp / 2;
                numMon = numMon * 2;
            } else {
                sumAttack += numMon;
                break;
            }
        }

        System.out.println(sumAttack);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) long hp = scanner.nextLong(); hp scanner.nextLong() scanner.nextLong scanner scanner.close() scanner.close scanner long sumAttack = 0; sumAttack 0 long nextHp = hp; nextHp hp long numMon = 1; numMon 1 while(true) {
            if(nextHp != 1) {
                sumAttack += numMon;
                nextHp = nextHp / 2;
                numMon = numMon * 2;
            } else {
                sumAttack += numMon;
                break;
            }
        } true {
            if(nextHp != 1) {
                sumAttack += numMon;
                nextHp = nextHp / 2;
                numMon = numMon * 2;
            } else {
                sumAttack += numMon;
                break;
            }
        } if(nextHp != 1) {
                sumAttack += numMon;
                nextHp = nextHp / 2;
                numMon = numMon * 2;
            } else {
                sumAttack += numMon;
                break;
            } nextHp != 1 nextHp 1 {
                sumAttack += numMon;
                nextHp = nextHp / 2;
                numMon = numMon * 2;
            } sumAttack += numMon sumAttack numMon nextHp = nextHp / 2 nextHp nextHp / 2 nextHp 2 numMon = numMon * 2 numMon numMon * 2 numMon 2 {
                sumAttack += numMon;
                break;
            } sumAttack += numMon sumAttack numMon break; System.out.println(sumAttack) System.out.println System.out System System.out sumAttack String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long hp = scanner.nextLong();
        scanner.close();

        long sumAttack = 0;
        long nextHp = hp;
        long numMon = 1;
        while(true) {
            if(nextHp != 1) {
                sumAttack += numMon;
                nextHp = nextHp / 2;
                numMon = numMon * 2;
            } else {
                sumAttack += numMon;
                break;
            }
        }

        System.out.println(sumAttack);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long hp = scanner.nextLong();
        scanner.close();

        long sumAttack = 0;
        long nextHp = hp;
        long numMon = 1;
        while(true) {
            if(nextHp != 1) {
                sumAttack += numMon;
                nextHp = nextHp / 2;
                numMon = numMon * 2;
            } else {
                sumAttack += numMon;
                break;
            }
        }

        System.out.println(sumAttack);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long hp = scanner.nextLong();
        scanner.close();

        long sumAttack = 0;
        long nextHp = hp;
        long numMon = 1;
        while(true) {
            if(nextHp != 1) {
                sumAttack += numMon;
                nextHp = nextHp / 2;
                numMon = numMon * 2;
            } else {
                sumAttack += numMon;
                break;
            }
        }

        System.out.println(sumAttack);
    }
}