import java.util.*;

public class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    long all = 1;
    long B = 1;
    long H = sc.nextLong();   //the HP of monster
    double X = Math.log(H) / Math.log(2);
    long A = (int) X;

    for (int i = 0; i <= A-1; i++){
      B = B * 2;
      all += B;
    }
    System.out.println(all);
  }
} import java.util.*; util.* java public class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    long all = 1;
    long B = 1;
    long H = sc.nextLong();   //the HP of monster
    double X = Math.log(H) / Math.log(2);
    long A = (int) X;

    for (int i = 0; i <= A-1; i++){
      B = B * 2;
      all += B;
    }
    System.out.println(all);
  }
} Main public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    long all = 1;
    long B = 1;
    long H = sc.nextLong();   //the HP of monster
    double X = Math.log(H) / Math.log(2);
    long A = (int) X;

    for (int i = 0; i <= A-1; i++){
      B = B * 2;
      all += B;
    }
    System.out.println(all);
  } main {

    Scanner sc = new Scanner(System.in);
    long all = 1;
    long B = 1;
    long H = sc.nextLong();   //the HP of monster
    double X = Math.log(H) / Math.log(2);
    long A = (int) X;

    for (int i = 0; i <= A-1; i++){
      B = B * 2;
      all += B;
    }
    System.out.println(all);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long all = 1; all 1 long B = 1; B 1 long H = sc.nextLong(); H sc.nextLong() sc.nextLong sc double X = Math.log(H) / Math.log(2); X Math.log(H) / Math.log(2) Math.log(H) Math.log Math H Math.log(2) Math.log Math 2 long A = (int) X; A (int) X for (int i = 0; i <= A-1; i++){
      B = B * 2;
      all += B;
    } int i = 0; int i = 0; i 0 i <= A-1 i A-1 A 1 i++ i++ i {
      B = B * 2;
      all += B;
    } {
      B = B * 2;
      all += B;
    } B = B * 2 B B * 2 B 2 all += B all B System.out.println(all) System.out.println System.out System System.out all String[] args args public class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    long all = 1;
    long B = 1;
    long H = sc.nextLong();   //the HP of monster
    double X = Math.log(H) / Math.log(2);
    long A = (int) X;

    for (int i = 0; i <= A-1; i++){
      B = B * 2;
      all += B;
    }
    System.out.println(all);
  }
} public class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    long all = 1;
    long B = 1;
    long H = sc.nextLong();   //the HP of monster
    double X = Math.log(H) / Math.log(2);
    long A = (int) X;

    for (int i = 0; i <= A-1; i++){
      B = B * 2;
      all += B;
    }
    System.out.println(all);
  }
} Main
import java.util.*;

public class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    long all = 1;
    long B = 1;
    long H = sc.nextLong();   //the HP of monster
    double X = Math.log(H) / Math.log(2);
    long A = (int) X;

    for (int i = 0; i <= A-1; i++){
      B = B * 2;
      all += B;
    }
    System.out.println(all);
  }
}
