import java.util.*;
public class Main{

  static void findAns(long n,long ans,int count){

    if(n>1){
      ans+=Math.pow(2,count);
      ++count;
      findAns(n/2,ans,count);
    }
    else{
      ans+=Math.pow(2,count);
      System.out.println(ans);
    }
  }

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

  static void findAns(long n,long ans,int count){

    if(n>1){
      ans+=Math.pow(2,count);
      ++count;
      findAns(n/2,ans,count);
    }
    else{
      ans+=Math.pow(2,count);
      System.out.println(ans);
    }
  }

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

    if(n>1){
      ans+=Math.pow(2,count);
      ++count;
      findAns(n/2,ans,count);
    }
    else{
      ans+=Math.pow(2,count);
      System.out.println(ans);
    }
  } findAns {

    if(n>1){
      ans+=Math.pow(2,count);
      ++count;
      findAns(n/2,ans,count);
    }
    else{
      ans+=Math.pow(2,count);
      System.out.println(ans);
    }
  } if(n>1){
      ans+=Math.pow(2,count);
      ++count;
      findAns(n/2,ans,count);
    }
    else{
      ans+=Math.pow(2,count);
      System.out.println(ans);
    } n>1 n 1 {
      ans+=Math.pow(2,count);
      ++count;
      findAns(n/2,ans,count);
    } ans+=Math.pow(2,count) ans Math.pow(2,count) Math.pow Math 2 count ++count count findAns(n/2,ans,count) findAns n/2 n 2 ans count {
      ans+=Math.pow(2,count);
      System.out.println(ans);
    } ans+=Math.pow(2,count) ans Math.pow(2,count) Math.pow Math 2 count System.out.println(ans) System.out.println System.out System System.out ans long n n long ans ans int count count public static void main(String args[]){
    Scanner sc=new Scanner(System.in);
    long n=sc.nextLong();
    long ans=0;
    findAns(n,ans,0);
  } main {
    Scanner sc=new Scanner(System.in);
    long n=sc.nextLong();
    long ans=0;
    findAns(n,ans,0);
  } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) long n=sc.nextLong(); n sc.nextLong() sc.nextLong sc long ans=0; ans 0 findAns(n,ans,0) findAns n ans 0 String args[] args public class Main{

  static void findAns(long n,long ans,int count){

    if(n>1){
      ans+=Math.pow(2,count);
      ++count;
      findAns(n/2,ans,count);
    }
    else{
      ans+=Math.pow(2,count);
      System.out.println(ans);
    }
  }

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

  static void findAns(long n,long ans,int count){

    if(n>1){
      ans+=Math.pow(2,count);
      ++count;
      findAns(n/2,ans,count);
    }
    else{
      ans+=Math.pow(2,count);
      System.out.println(ans);
    }
  }

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

  static void findAns(long n,long ans,int count){

    if(n>1){
      ans+=Math.pow(2,count);
      ++count;
      findAns(n/2,ans,count);
    }
    else{
      ans+=Math.pow(2,count);
      System.out.println(ans);
    }
  }

  public static void main(String args[]){
    Scanner sc=new Scanner(System.in);
    long n=sc.nextLong();
    long ans=0;
    findAns(n,ans,0);
  }
}
