import java.util.*;

class Main{

  public static void main(String args[]){

    Scanner s=new Scanner(System.in);
    long H=s.nextLong();
    long cnt=0;
    long plus=1;
    for(;;){
    if(H==1) break;
    H/=2;
    cnt+=plus;
    plus*=2;
    }
    System.out.println(cnt+plus);
  }  
} import java.util.*; util.* java class Main{

  public static void main(String args[]){

    Scanner s=new Scanner(System.in);
    long H=s.nextLong();
    long cnt=0;
    long plus=1;
    for(;;){
    if(H==1) break;
    H/=2;
    cnt+=plus;
    plus*=2;
    }
    System.out.println(cnt+plus);
  }  
} Main public static void main(String args[]){

    Scanner s=new Scanner(System.in);
    long H=s.nextLong();
    long cnt=0;
    long plus=1;
    for(;;){
    if(H==1) break;
    H/=2;
    cnt+=plus;
    plus*=2;
    }
    System.out.println(cnt+plus);
  } main {

    Scanner s=new Scanner(System.in);
    long H=s.nextLong();
    long cnt=0;
    long plus=1;
    for(;;){
    if(H==1) break;
    H/=2;
    cnt+=plus;
    plus*=2;
    }
    System.out.println(cnt+plus);
  } Scanner s=new Scanner(System.in); s new Scanner(System.in) long H=s.nextLong(); H s.nextLong() s.nextLong s long cnt=0; cnt 0 long plus=1; plus 1 for(;;){
    if(H==1) break;
    H/=2;
    cnt+=plus;
    plus*=2;
    } ; {
    if(H==1) break;
    H/=2;
    cnt+=plus;
    plus*=2;
    } {
    if(H==1) break;
    H/=2;
    cnt+=plus;
    plus*=2;
    } if(H==1) break; H==1 H 1 break; H/=2 H 2 cnt+=plus cnt plus plus*=2 plus 2 System.out.println(cnt+plus) System.out.println System.out System System.out cnt+plus cnt plus String args[] args
import java.util.*;

class Main{

  public static void main(String args[]){

    Scanner s=new Scanner(System.in);
    long H=s.nextLong();
    long cnt=0;
    long plus=1;
    for(;;){
    if(H==1) break;
    H/=2;
    cnt+=plus;
    plus*=2;
    }
    System.out.println(cnt+plus);
  }  
}