import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    System.out.println(solve(n));
    sc.close();
  }
  
  public static long solve(long h) {
    if(h == 1) return 1;
    return 2*solve(h/2)+1;
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    System.out.println(solve(n));
    sc.close();
  }
  
  public static long solve(long h) {
    if(h == 1) return 1;
    return 2*solve(h/2)+1;
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    System.out.println(solve(n));
    sc.close();
  } main {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    System.out.println(solve(n));
    sc.close();
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long n = sc.nextLong(); n sc.nextLong() sc.nextLong sc System.out.println(solve(n)) System.out.println System.out System System.out solve(n) solve n sc.close() sc.close sc String[] args args public static long solve(long h) {
    if(h == 1) return 1;
    return 2*solve(h/2)+1;
  } solve {
    if(h == 1) return 1;
    return 2*solve(h/2)+1;
  } if(h == 1) return 1; h == 1 h 1 return 1; 1 return 2*solve(h/2)+1; 2*solve(h/2)+1 2*solve(h/2) 2 solve(h/2) solve h/2 h 2 1 long h h public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    System.out.println(solve(n));
    sc.close();
  }
  
  public static long solve(long h) {
    if(h == 1) return 1;
    return 2*solve(h/2)+1;
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    System.out.println(solve(n));
    sc.close();
  }
  
  public static long solve(long h) {
    if(h == 1) return 1;
    return 2*solve(h/2)+1;
  }
} Main
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    System.out.println(solve(n));
    sc.close();
  }
  
  public static long solve(long h) {
    if(h == 1) return 1;
    return 2*solve(h/2)+1;
  }
}