import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long H = sc.nextLong();
    long answer =0;
    long enmcnt =1;
    while(H!=1){
      answer = answer + enmcnt;
      H=H/2;
      enmcnt=enmcnt*2;
      //System.out.println(answer);
    }
    answer = answer + enmcnt;
    System.out.println(answer);
    
    
    
  }
  

  
} 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 answer =0;
    long enmcnt =1;
    while(H!=1){
      answer = answer + enmcnt;
      H=H/2;
      enmcnt=enmcnt*2;
      //System.out.println(answer);
    }
    answer = answer + enmcnt;
    System.out.println(answer);
    
    
    
  }
  

  
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long H = sc.nextLong();
    long answer =0;
    long enmcnt =1;
    while(H!=1){
      answer = answer + enmcnt;
      H=H/2;
      enmcnt=enmcnt*2;
      //System.out.println(answer);
    }
    answer = answer + enmcnt;
    System.out.println(answer);
    
    
    
  } main {
    Scanner sc = new Scanner(System.in);
    long H = sc.nextLong();
    long answer =0;
    long enmcnt =1;
    while(H!=1){
      answer = answer + enmcnt;
      H=H/2;
      enmcnt=enmcnt*2;
      //System.out.println(answer);
    }
    answer = answer + enmcnt;
    System.out.println(answer);
    
    
    
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long H = sc.nextLong(); H sc.nextLong() sc.nextLong sc long answer =0; answer 0 long enmcnt =1; enmcnt 1 while(H!=1){
      answer = answer + enmcnt;
      H=H/2;
      enmcnt=enmcnt*2;
      //System.out.println(answer);
    } H!=1 H 1 {
      answer = answer + enmcnt;
      H=H/2;
      enmcnt=enmcnt*2;
      //System.out.println(answer);
    } answer = answer + enmcnt answer answer + enmcnt answer enmcnt H=H/2 H H/2 H 2 enmcnt=enmcnt*2 enmcnt enmcnt*2 enmcnt 2 answer = answer + enmcnt answer answer + enmcnt answer enmcnt System.out.println(answer) System.out.println System.out System System.out answer String[] args args public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long H = sc.nextLong();
    long answer =0;
    long enmcnt =1;
    while(H!=1){
      answer = answer + enmcnt;
      H=H/2;
      enmcnt=enmcnt*2;
      //System.out.println(answer);
    }
    answer = answer + enmcnt;
    System.out.println(answer);
    
    
    
  }
  

  
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long H = sc.nextLong();
    long answer =0;
    long enmcnt =1;
    while(H!=1){
      answer = answer + enmcnt;
      H=H/2;
      enmcnt=enmcnt*2;
      //System.out.println(answer);
    }
    answer = answer + enmcnt;
    System.out.println(answer);
    
    
    
  }
  

  
} Main
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long H = sc.nextLong();
    long answer =0;
    long enmcnt =1;
    while(H!=1){
      answer = answer + enmcnt;
      H=H/2;
      enmcnt=enmcnt*2;
      //System.out.println(answer);
    }
    answer = answer + enmcnt;
    System.out.println(answer);
    
    
    
  }
  

  
}