import java.util.Scanner;

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

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

    static long attack(long hp) {
        if (hp == 1) {
            return 1;
        }
        return attack(hp / 2) * 2 + 1;
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        System.out.println(attack(H));
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        System.out.println(attack(H));
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long H = sc.nextLong(); H sc.nextLong() sc.nextLong sc System.out.println(attack(H)) System.out.println System.out System System.out attack(H) attack H sc.close() sc.close sc String[] args args static long attack(long hp) {
        if (hp == 1) {
            return 1;
        }
        return attack(hp / 2) * 2 + 1;
    } attack {
        if (hp == 1) {
            return 1;
        }
        return attack(hp / 2) * 2 + 1;
    } if (hp == 1) {
            return 1;
        } hp == 1 hp 1 {
            return 1;
        } return 1; 1 return attack(hp / 2) * 2 + 1; attack(hp / 2) * 2 + 1 attack(hp / 2) * 2 attack(hp / 2) attack hp / 2 hp 2 2 1 long hp hp public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        System.out.println(attack(H));
        sc.close();
    }

    static long attack(long hp) {
        if (hp == 1) {
            return 1;
        }
        return attack(hp / 2) * 2 + 1;
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        System.out.println(attack(H));
        sc.close();
    }

    static long attack(long hp) {
        if (hp == 1) {
            return 1;
        }
        return attack(hp / 2) * 2 + 1;
    }
} Main
import java.util.Scanner;

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

    static long attack(long hp) {
        if (hp == 1) {
            return 1;
        }
        return attack(hp / 2) * 2 + 1;
    }
}