import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long h = sc.nextLong();
    int count = 0;
    long ans = 0;

    while(h>0){
      h = h/2;
      count++;
    }
    
    for(int i = 0 ; i < count ; ++i){
        ans += (long)Math.pow(2,i);
    }
        
    System.out.println(ans);

  }
} import java.util.*; util.* java public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long h = sc.nextLong();
    int count = 0;
    long ans = 0;

    while(h>0){
      h = h/2;
      count++;
    }
    
    for(int i = 0 ; i < count ; ++i){
        ans += (long)Math.pow(2,i);
    }
        
    System.out.println(ans);

  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long h = sc.nextLong();
    int count = 0;
    long ans = 0;

    while(h>0){
      h = h/2;
      count++;
    }
    
    for(int i = 0 ; i < count ; ++i){
        ans += (long)Math.pow(2,i);
    }
        
    System.out.println(ans);

  } main {
    Scanner sc = new Scanner(System.in);
    long h = sc.nextLong();
    int count = 0;
    long ans = 0;

    while(h>0){
      h = h/2;
      count++;
    }
    
    for(int i = 0 ; i < count ; ++i){
        ans += (long)Math.pow(2,i);
    }
        
    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 int count = 0; count 0 long ans = 0; ans 0 while(h>0){
      h = h/2;
      count++;
    } h>0 h 0 {
      h = h/2;
      count++;
    } h = h/2 h h/2 h 2 count++ count for(int i = 0 ; i < count ; ++i){
        ans += (long)Math.pow(2,i);
    } int i = 0 ; int i = 0 ; i 0 i < count i count ++i ++i i {
        ans += (long)Math.pow(2,i);
    } {
        ans += (long)Math.pow(2,i);
    } ans += (long)Math.pow(2,i) ans (long)Math.pow(2,i) Math.pow Math 2 i 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();
    int count = 0;
    long ans = 0;

    while(h>0){
      h = h/2;
      count++;
    }
    
    for(int i = 0 ; i < count ; ++i){
        ans += (long)Math.pow(2,i);
    }
        
    System.out.println(ans);

  }
} public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long h = sc.nextLong();
    int count = 0;
    long ans = 0;

    while(h>0){
      h = h/2;
      count++;
    }
    
    for(int i = 0 ; i < count ; ++i){
        ans += (long)Math.pow(2,i);
    }
        
    System.out.println(ans);

  }
} Main
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long h = sc.nextLong();
    int count = 0;
    long ans = 0;

    while(h>0){
      h = h/2;
      count++;
    }
    
    for(int i = 0 ; i < count ; ++i){
        ans += (long)Math.pow(2,i);
    }
        
    System.out.println(ans);

  }
}