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

    long h = sc.nextLong();
    long count = 0;
    long n = h;
    long a = 1;


    for (int i = 1;n>0;i++ ) {
      if (n>1) {
        n=n/2;
        a = a*2;
        count+=2*a;
      }
      if (n==1) {
        n=0;

      }
    }

    System.out.println(count/2+1);
  }
} import java.util.*; util.* java public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);

    long h = sc.nextLong();
    long count = 0;
    long n = h;
    long a = 1;


    for (int i = 1;n>0;i++ ) {
      if (n>1) {
        n=n/2;
        a = a*2;
        count+=2*a;
      }
      if (n==1) {
        n=0;

      }
    }

    System.out.println(count/2+1);
  }
} Main public static void main(String[]args){
    Scanner sc = new Scanner(System.in);

    long h = sc.nextLong();
    long count = 0;
    long n = h;
    long a = 1;


    for (int i = 1;n>0;i++ ) {
      if (n>1) {
        n=n/2;
        a = a*2;
        count+=2*a;
      }
      if (n==1) {
        n=0;

      }
    }

    System.out.println(count/2+1);
  } main {
    Scanner sc = new Scanner(System.in);

    long h = sc.nextLong();
    long count = 0;
    long n = h;
    long a = 1;


    for (int i = 1;n>0;i++ ) {
      if (n>1) {
        n=n/2;
        a = a*2;
        count+=2*a;
      }
      if (n==1) {
        n=0;

      }
    }

    System.out.println(count/2+1);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long h = sc.nextLong(); h sc.nextLong() sc.nextLong sc long count = 0; count 0 long n = h; n h long a = 1; a 1 for (int i = 1;n>0;i++ ) {
      if (n>1) {
        n=n/2;
        a = a*2;
        count+=2*a;
      }
      if (n==1) {
        n=0;

      }
    } int i = 1; int i = 1; i 1 n>0 n 0 i++ i++ i {
      if (n>1) {
        n=n/2;
        a = a*2;
        count+=2*a;
      }
      if (n==1) {
        n=0;

      }
    } {
      if (n>1) {
        n=n/2;
        a = a*2;
        count+=2*a;
      }
      if (n==1) {
        n=0;

      }
    } if (n>1) {
        n=n/2;
        a = a*2;
        count+=2*a;
      } n>1 n 1 {
        n=n/2;
        a = a*2;
        count+=2*a;
      } n=n/2 n n/2 n 2 a = a*2 a a*2 a 2 count+=2*a count 2*a 2 a if (n==1) {
        n=0;

      } n==1 n 1 {
        n=0;

      } n=0 n 0 System.out.println(count/2+1) System.out.println System.out System System.out count/2+1 count/2 count 2 1 String[]args args public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);

    long h = sc.nextLong();
    long count = 0;
    long n = h;
    long a = 1;


    for (int i = 1;n>0;i++ ) {
      if (n>1) {
        n=n/2;
        a = a*2;
        count+=2*a;
      }
      if (n==1) {
        n=0;

      }
    }

    System.out.println(count/2+1);
  }
} public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);

    long h = sc.nextLong();
    long count = 0;
    long n = h;
    long a = 1;


    for (int i = 1;n>0;i++ ) {
      if (n>1) {
        n=n/2;
        a = a*2;
        count+=2*a;
      }
      if (n==1) {
        n=0;

      }
    }

    System.out.println(count/2+1);
  }
} Main
import java.util.*;
public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);

    long h = sc.nextLong();
    long count = 0;
    long n = h;
    long a = 1;


    for (int i = 1;n>0;i++ ) {
      if (n>1) {
        n=n/2;
        a = a*2;
        count+=2*a;
      }
      if (n==1) {
        n=0;

      }
    }

    System.out.println(count/2+1);
  }
}
