import java.util.Scanner;
import java.util.Queue;
import java.util.ArrayDeque;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long h = Long.parseLong(sc.next());
    Queue<Long> queue = new ArrayDeque<>();
    queue.add(h);
    Long vital;
    Long sum = 0L;
    Long base = 1L;
    while(!queue.isEmpty()){
      vital = queue.poll();
      sum+=base;
      base*=2;
      if(vital>1){
        queue.add(vital/2);
      }
    }
    System.out.print(sum);
    System.out.flush();
  }
} import java.util.Scanner; Scanner java.util import java.util.Queue; Queue java.util import java.util.ArrayDeque; ArrayDeque java.util class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long h = Long.parseLong(sc.next());
    Queue<Long> queue = new ArrayDeque<>();
    queue.add(h);
    Long vital;
    Long sum = 0L;
    Long base = 1L;
    while(!queue.isEmpty()){
      vital = queue.poll();
      sum+=base;
      base*=2;
      if(vital>1){
        queue.add(vital/2);
      }
    }
    System.out.print(sum);
    System.out.flush();
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long h = Long.parseLong(sc.next());
    Queue<Long> queue = new ArrayDeque<>();
    queue.add(h);
    Long vital;
    Long sum = 0L;
    Long base = 1L;
    while(!queue.isEmpty()){
      vital = queue.poll();
      sum+=base;
      base*=2;
      if(vital>1){
        queue.add(vital/2);
      }
    }
    System.out.print(sum);
    System.out.flush();
  } main {
    Scanner sc = new Scanner(System.in);
    long h = Long.parseLong(sc.next());
    Queue<Long> queue = new ArrayDeque<>();
    queue.add(h);
    Long vital;
    Long sum = 0L;
    Long base = 1L;
    while(!queue.isEmpty()){
      vital = queue.poll();
      sum+=base;
      base*=2;
      if(vital>1){
        queue.add(vital/2);
      }
    }
    System.out.print(sum);
    System.out.flush();
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long h = Long.parseLong(sc.next()); h Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc Queue<Long> queue = new ArrayDeque<>(); queue new ArrayDeque<>() queue.add(h) queue.add queue h Long vital; vital Long sum = 0L; sum 0L Long base = 1L; base 1L while(!queue.isEmpty()){
      vital = queue.poll();
      sum+=base;
      base*=2;
      if(vital>1){
        queue.add(vital/2);
      }
    } !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
      vital = queue.poll();
      sum+=base;
      base*=2;
      if(vital>1){
        queue.add(vital/2);
      }
    } vital = queue.poll() vital queue.poll() queue.poll queue sum+=base sum base base*=2 base 2 if(vital>1){
        queue.add(vital/2);
      } vital>1 vital 1 {
        queue.add(vital/2);
      } queue.add(vital/2) queue.add queue vital/2 vital 2 System.out.print(sum) System.out.print System.out System System.out sum System.out.flush() System.out.flush System.out System System.out String[] args args
import java.util.Scanner;
import java.util.Queue;
import java.util.ArrayDeque;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long h = Long.parseLong(sc.next());
    Queue<Long> queue = new ArrayDeque<>();
    queue.add(h);
    Long vital;
    Long sum = 0L;
    Long base = 1L;
    while(!queue.isEmpty()){
      vital = queue.poll();
      sum+=base;
      base*=2;
      if(vital>1){
        queue.add(vital/2);
      }
    }
    System.out.print(sum);
    System.out.flush();
  }
}