import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    long h = Long.valueOf(sc.next());

    int step = 0;
    for (long n = h; h > 0; h /= 2) {
      step++;
    }

    System.out.println((long)Math.pow(2, step)-1);

    sc.close();
  }

} import java.util.Scanner; Scanner java.util public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    long h = Long.valueOf(sc.next());

    int step = 0;
    for (long n = h; h > 0; h /= 2) {
      step++;
    }

    System.out.println((long)Math.pow(2, step)-1);

    sc.close();
  }

} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    long h = Long.valueOf(sc.next());

    int step = 0;
    for (long n = h; h > 0; h /= 2) {
      step++;
    }

    System.out.println((long)Math.pow(2, step)-1);

    sc.close();
  } main {
    Scanner sc = new Scanner(System.in);

    long h = Long.valueOf(sc.next());

    int step = 0;
    for (long n = h; h > 0; h /= 2) {
      step++;
    }

    System.out.println((long)Math.pow(2, step)-1);

    sc.close();
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long h = Long.valueOf(sc.next()); h Long.valueOf(sc.next()) Long.valueOf Long sc.next() sc.next sc int step = 0; step 0 for (long n = h; h > 0; h /= 2) {
      step++;
    } long n = h; long n = h; n h h > 0 h 0 h /= 2 h /= 2 h 2 {
      step++;
    } {
      step++;
    } step++ step System.out.println((long)Math.pow(2, step)-1) System.out.println System.out System System.out (long)Math.pow(2, step)-1 (long)Math.pow(2, step) Math.pow Math 2 step 1 sc.close() sc.close sc String[] args args public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    long h = Long.valueOf(sc.next());

    int step = 0;
    for (long n = h; h > 0; h /= 2) {
      step++;
    }

    System.out.println((long)Math.pow(2, step)-1);

    sc.close();
  }

} public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    long h = Long.valueOf(sc.next());

    int step = 0;
    for (long n = h; h > 0; h /= 2) {
      step++;
    }

    System.out.println((long)Math.pow(2, step)-1);

    sc.close();
  }

} Main
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    long h = Long.valueOf(sc.next());

    int step = 0;
    for (long n = h; h > 0; h /= 2) {
      step++;
    }

    System.out.println((long)Math.pow(2, step)-1);

    sc.close();
  }

}
