import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    long h = Long.parseLong(sc.next());
    if (h == 1) {
      pw.println("1");
      return;
    }
    long ans = 0;
    long numberOfNodes = 1;
    long nextH = h;
    while (nextH != 1) {
      ans += numberOfNodes;
      numberOfNodes *= 2;
      nextH /= 2;
    }
    ans += numberOfNodes;
    pw.println(ans);
  }
} import java.io.InputStream; InputStream java.io import java.io.PrintStream; PrintStream java.io import java.util.Scanner; Scanner java.util public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    long h = Long.parseLong(sc.next());
    if (h == 1) {
      pw.println("1");
      return;
    }
    long ans = 0;
    long numberOfNodes = 1;
    long nextH = h;
    while (nextH != 1) {
      ans += numberOfNodes;
      numberOfNodes *= 2;
      nextH /= 2;
    }
    ans += numberOfNodes;
    pw.println(ans);
  }
} Main public static void main(String[] args) {
    resolve(System.in, System.out);
  } main {
    resolve(System.in, System.out);
  } resolve(System.in, System.out) resolve System.in System System.in System.out System System.out String[] args args static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    long h = Long.parseLong(sc.next());
    if (h == 1) {
      pw.println("1");
      return;
    }
    long ans = 0;
    long numberOfNodes = 1;
    long nextH = h;
    while (nextH != 1) {
      ans += numberOfNodes;
      numberOfNodes *= 2;
      nextH /= 2;
    }
    ans += numberOfNodes;
    pw.println(ans);
  } resolve {
    Scanner sc = new Scanner(is);
    long h = Long.parseLong(sc.next());
    if (h == 1) {
      pw.println("1");
      return;
    }
    long ans = 0;
    long numberOfNodes = 1;
    long nextH = h;
    while (nextH != 1) {
      ans += numberOfNodes;
      numberOfNodes *= 2;
      nextH /= 2;
    }
    ans += numberOfNodes;
    pw.println(ans);
  } Scanner sc = new Scanner(is); sc new Scanner(is) long h = Long.parseLong(sc.next()); h Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc if (h == 1) {
      pw.println("1");
      return;
    } h == 1 h 1 {
      pw.println("1");
      return;
    } pw.println("1") pw.println pw "1" return; long ans = 0; ans 0 long numberOfNodes = 1; numberOfNodes 1 long nextH = h; nextH h while (nextH != 1) {
      ans += numberOfNodes;
      numberOfNodes *= 2;
      nextH /= 2;
    } nextH != 1 nextH 1 {
      ans += numberOfNodes;
      numberOfNodes *= 2;
      nextH /= 2;
    } ans += numberOfNodes ans numberOfNodes numberOfNodes *= 2 numberOfNodes 2 nextH /= 2 nextH 2 ans += numberOfNodes ans numberOfNodes pw.println(ans) pw.println pw ans InputStream is is PrintStream pw pw public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    long h = Long.parseLong(sc.next());
    if (h == 1) {
      pw.println("1");
      return;
    }
    long ans = 0;
    long numberOfNodes = 1;
    long nextH = h;
    while (nextH != 1) {
      ans += numberOfNodes;
      numberOfNodes *= 2;
      nextH /= 2;
    }
    ans += numberOfNodes;
    pw.println(ans);
  }
} public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    long h = Long.parseLong(sc.next());
    if (h == 1) {
      pw.println("1");
      return;
    }
    long ans = 0;
    long numberOfNodes = 1;
    long nextH = h;
    while (nextH != 1) {
      ans += numberOfNodes;
      numberOfNodes *= 2;
      nextH /= 2;
    }
    ans += numberOfNodes;
    pw.println(ans);
  }
} Main
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    long h = Long.parseLong(sc.next());
    if (h == 1) {
      pw.println("1");
      return;
    }
    long ans = 0;
    long numberOfNodes = 1;
    long nextH = h;
    while (nextH != 1) {
      ans += numberOfNodes;
      numberOfNodes *= 2;
      nextH /= 2;
    }
    ans += numberOfNodes;
    pw.println(ans);
  }
}
