import java.util.*;
import java.io.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long h = sc.nextLong();
    double value = Math.log(h) / Math.log(2.0);
    int pow = (int) value + 1;
    long ans = (long)Math.pow(2, (double)pow) - (long)1;
    System.out.println(ans);
  }
} import java.util.*; util.* java import java.io.*; io.* java public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long h = sc.nextLong();
    double value = Math.log(h) / Math.log(2.0);
    int pow = (int) value + 1;
    long ans = (long)Math.pow(2, (double)pow) - (long)1;
    System.out.println(ans);
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long h = sc.nextLong();
    double value = Math.log(h) / Math.log(2.0);
    int pow = (int) value + 1;
    long ans = (long)Math.pow(2, (double)pow) - (long)1;
    System.out.println(ans);
  } main {
    Scanner sc = new Scanner(System.in);
    long h = sc.nextLong();
    double value = Math.log(h) / Math.log(2.0);
    int pow = (int) value + 1;
    long ans = (long)Math.pow(2, (double)pow) - (long)1;
    System.out.println(ans);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long h = sc.nextLong(); h sc.nextLong() sc.nextLong sc double value = Math.log(h) / Math.log(2.0); value Math.log(h) / Math.log(2.0) Math.log(h) Math.log Math h Math.log(2.0) Math.log Math 2.0 int pow = (int) value + 1; pow (int) value + 1 (int) value 1 long ans = (long)Math.pow(2, (double)pow) - (long)1; ans (long)Math.pow(2, (double)pow) - (long)1 (long)Math.pow(2, (double)pow) Math.pow Math 2 (double)pow (long)1 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long h = sc.nextLong();
    double value = Math.log(h) / Math.log(2.0);
    int pow = (int) value + 1;
    long ans = (long)Math.pow(2, (double)pow) - (long)1;
    System.out.println(ans);
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long h = sc.nextLong();
    double value = Math.log(h) / Math.log(2.0);
    int pow = (int) value + 1;
    long ans = (long)Math.pow(2, (double)pow) - (long)1;
    System.out.println(ans);
  }
} Main
import java.util.*;
import java.io.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long h = sc.nextLong();
    double value = Math.log(h) / Math.log(2.0);
    int pow = (int) value + 1;
    long ans = (long)Math.pow(2, (double)pow) - (long)1;
    System.out.println(ans);
  }
}