import java.util.*;
import java.io.*;
import java.lang.Math;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long h = sc.nextLong();
    long attacks = 0;
    long temp =1;
    while(h>0){
      attacks+=temp;
      temp*=2;
      h/=2;
    }
    System.out.println(attacks);
  }
}
      
       import java.util.*; util.* java import java.io.*; io.* java import java.lang.Math; Math java.lang class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long h = sc.nextLong();
    long attacks = 0;
    long temp =1;
    while(h>0){
      attacks+=temp;
      temp*=2;
      h/=2;
    }
    System.out.println(attacks);
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long h = sc.nextLong();
    long attacks = 0;
    long temp =1;
    while(h>0){
      attacks+=temp;
      temp*=2;
      h/=2;
    }
    System.out.println(attacks);
  } main {
    Scanner sc = new Scanner(System.in);
    long h = sc.nextLong();
    long attacks = 0;
    long temp =1;
    while(h>0){
      attacks+=temp;
      temp*=2;
      h/=2;
    }
    System.out.println(attacks);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long h = sc.nextLong(); h sc.nextLong() sc.nextLong sc long attacks = 0; attacks 0 long temp =1; temp 1 while(h>0){
      attacks+=temp;
      temp*=2;
      h/=2;
    } h>0 h 0 {
      attacks+=temp;
      temp*=2;
      h/=2;
    } attacks+=temp attacks temp temp*=2 temp 2 h/=2 h 2 System.out.println(attacks) System.out.println System.out System System.out attacks String[] args args
import java.util.*;
import java.io.*;
import java.lang.Math;

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