import java.util.*;
public class Main {

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

      System.out.println(recursive(n));
  }

  static Map<Long, Long> cache = new HashMap<>();
  
  private static long recursive(long n) {
    if(cache.containsKey(n))
      return cache.get(n);
    if(n == 1)
      return 1;

    long sum = recursive(n / 2) * 2 + 1;

    cache.put(n, sum);
    return sum;
  }
} import java.util.*; util.* java public class Main {

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

      System.out.println(recursive(n));
  }

  static Map<Long, Long> cache = new HashMap<>();
  
  private static long recursive(long n) {
    if(cache.containsKey(n))
      return cache.get(n);
    if(n == 1)
      return 1;

    long sum = recursive(n / 2) * 2 + 1;

    cache.put(n, sum);
    return sum;
  }
} Main static Map<Long, Long> cache = new HashMap<>(); cache new HashMap<>() public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      long n = sc.nextLong();

      System.out.println(recursive(n));
  } main { 
      Scanner sc = new Scanner(System.in);
      long n = sc.nextLong();

      System.out.println(recursive(n));
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long n = sc.nextLong(); n sc.nextLong() sc.nextLong sc System.out.println(recursive(n)) System.out.println System.out System System.out recursive(n) recursive n String[] args args private static long recursive(long n) {
    if(cache.containsKey(n))
      return cache.get(n);
    if(n == 1)
      return 1;

    long sum = recursive(n / 2) * 2 + 1;

    cache.put(n, sum);
    return sum;
  } recursive {
    if(cache.containsKey(n))
      return cache.get(n);
    if(n == 1)
      return 1;

    long sum = recursive(n / 2) * 2 + 1;

    cache.put(n, sum);
    return sum;
  } if(cache.containsKey(n))
      return cache.get(n); cache.containsKey(n) cache.containsKey cache n return cache.get(n); cache.get(n) cache.get cache n if(n == 1)
      return 1; n == 1 n 1 return 1; 1 long sum = recursive(n / 2) * 2 + 1; sum recursive(n / 2) * 2 + 1 recursive(n / 2) * 2 recursive(n / 2) recursive n / 2 n 2 2 1 cache.put(n, sum) cache.put cache n sum return sum; sum long n n public class Main {

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

      System.out.println(recursive(n));
  }

  static Map<Long, Long> cache = new HashMap<>();
  
  private static long recursive(long n) {
    if(cache.containsKey(n))
      return cache.get(n);
    if(n == 1)
      return 1;

    long sum = recursive(n / 2) * 2 + 1;

    cache.put(n, sum);
    return sum;
  }
} public class Main {

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

      System.out.println(recursive(n));
  }

  static Map<Long, Long> cache = new HashMap<>();
  
  private static long recursive(long n) {
    if(cache.containsKey(n))
      return cache.get(n);
    if(n == 1)
      return 1;

    long sum = recursive(n / 2) * 2 + 1;

    cache.put(n, sum);
    return sum;
  }
} Main
import java.util.*;
public class Main {

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

      System.out.println(recursive(n));
  }

  static Map<Long, Long> cache = new HashMap<>();
  
  private static long recursive(long n) {
    if(cache.containsKey(n))
      return cache.get(n);
    if(n == 1)
      return 1;

    long sum = recursive(n / 2) * 2 + 1;

    cache.put(n, sum);
    return sum;
  }
}