import java.util.Scanner;
import java.util.Arrays;


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

    int i = 0;
    for(i = 1;H > 1;i++){

      H = H/2;
    }


  /*  double N = 0;
    for(int n = 1;n <= i;n++){
      N += Math.pow(2, i-1)-1;
    }*/

  
  //  System.out.println(N);
    System.out.println((long)(Math.pow(2, i-1)+Math.pow(2, i-1)-1));
  }

} import java.util.Scanner; Scanner java.util import java.util.Arrays; Arrays java.util class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    long H = sc.nextLong();

    int i = 0;
    for(i = 1;H > 1;i++){

      H = H/2;
    }


  /*  double N = 0;
    for(int n = 1;n <= i;n++){
      N += Math.pow(2, i-1)-1;
    }*/

  
  //  System.out.println(N);
    System.out.println((long)(Math.pow(2, i-1)+Math.pow(2, i-1)-1));
  }

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

    int i = 0;
    for(i = 1;H > 1;i++){

      H = H/2;
    }


  /*  double N = 0;
    for(int n = 1;n <= i;n++){
      N += Math.pow(2, i-1)-1;
    }*/

  
  //  System.out.println(N);
    System.out.println((long)(Math.pow(2, i-1)+Math.pow(2, i-1)-1));
  } main {
    Scanner sc = new Scanner(System.in);
    long H = sc.nextLong();

    int i = 0;
    for(i = 1;H > 1;i++){

      H = H/2;
    }


  /*  double N = 0;
    for(int n = 1;n <= i;n++){
      N += Math.pow(2, i-1)-1;
    }*/

  
  //  System.out.println(N);
    System.out.println((long)(Math.pow(2, i-1)+Math.pow(2, i-1)-1));
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long H = sc.nextLong(); H sc.nextLong() sc.nextLong sc int i = 0; i 0 for(i = 1;H > 1;i++){

      H = H/2;
    } i = 1; i = 1 i 1 H > 1 H 1 i++ i++ i {

      H = H/2;
    } {

      H = H/2;
    } H = H/2 H H/2 H 2 System.out.println((long)(Math.pow(2, i-1)+Math.pow(2, i-1)-1)) System.out.println System.out System System.out (long)(Math.pow(2, i-1)+Math.pow(2, i-1)-1) Math.pow(2, i-1)+Math.pow(2, i-1) Math.pow(2, i-1) Math.pow Math 2 i-1 i 1 Math.pow(2, i-1) Math.pow Math 2 i-1 i 1 1 String args[] args
import java.util.Scanner;
import java.util.Arrays;


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

    int i = 0;
    for(i = 1;H > 1;i++){

      H = H/2;
    }


  /*  double N = 0;
    for(int n = 1;n <= i;n++){
      N += Math.pow(2, i-1)-1;
    }*/

  
  //  System.out.println(N);
    System.out.println((long)(Math.pow(2, i-1)+Math.pow(2, i-1)-1));
  }

}
