import java.util.Scanner;

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

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

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

    System.out.println(Attack);
    
  } main {
    
    Scanner sc = new Scanner(System.in);
    long H = sc.nextLong();
    long Attack = 0;
    long Monster = 1;
    
    while (H > 0) {
      Attack += Monster;
      H /= 2;
      Monster *= 2;
    }

    System.out.println(Attack);
    
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long H = sc.nextLong(); H sc.nextLong() sc.nextLong sc long Attack = 0; Attack 0 long Monster = 1; Monster 1 while (H > 0) {
      Attack += Monster;
      H /= 2;
      Monster *= 2;
    } H > 0 H 0 {
      Attack += Monster;
      H /= 2;
      Monster *= 2;
    } Attack += Monster Attack Monster H /= 2 H 2 Monster *= 2 Monster 2 System.out.println(Attack) System.out.println System.out System System.out Attack String[] args args
import java.util.Scanner;

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

    System.out.println(Attack);
    
  }
}