import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    long H =sc.nextLong();
    if(H==1){System.out.println(1);}
    else{
    long M[]=new long[100000];
    long N[]=new long[100000];
    M[0]=H;N[0]=1;int k=0;
    for(int i=1;i<100;i++){
      M[i]=(M[i-1]-M[i-1]%2)/2;
      N[i]=2*N[i-1];
      k=k+1;
    if(M[i]==1){break;}}
    long x=0;
    for(int j=0;j<=k;j++){
      x=x+N[j];}
    System.out.println(x);
  }}
} import java.util.*; util.* java public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    long H =sc.nextLong();
    if(H==1){System.out.println(1);}
    else{
    long M[]=new long[100000];
    long N[]=new long[100000];
    M[0]=H;N[0]=1;int k=0;
    for(int i=1;i<100;i++){
      M[i]=(M[i-1]-M[i-1]%2)/2;
      N[i]=2*N[i-1];
      k=k+1;
    if(M[i]==1){break;}}
    long x=0;
    for(int j=0;j<=k;j++){
      x=x+N[j];}
    System.out.println(x);
  }}
} Main public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    long H =sc.nextLong();
    if(H==1){System.out.println(1);}
    else{
    long M[]=new long[100000];
    long N[]=new long[100000];
    M[0]=H;N[0]=1;int k=0;
    for(int i=1;i<100;i++){
      M[i]=(M[i-1]-M[i-1]%2)/2;
      N[i]=2*N[i-1];
      k=k+1;
    if(M[i]==1){break;}}
    long x=0;
    for(int j=0;j<=k;j++){
      x=x+N[j];}
    System.out.println(x);
  }} main {
    Scanner sc =new Scanner(System.in);
    long H =sc.nextLong();
    if(H==1){System.out.println(1);}
    else{
    long M[]=new long[100000];
    long N[]=new long[100000];
    M[0]=H;N[0]=1;int k=0;
    for(int i=1;i<100;i++){
      M[i]=(M[i-1]-M[i-1]%2)/2;
      N[i]=2*N[i-1];
      k=k+1;
    if(M[i]==1){break;}}
    long x=0;
    for(int j=0;j<=k;j++){
      x=x+N[j];}
    System.out.println(x);
  }} Scanner sc =new Scanner(System.in); sc new Scanner(System.in) long H =sc.nextLong(); H sc.nextLong() sc.nextLong sc if(H==1){System.out.println(1);}
    else{
    long M[]=new long[100000];
    long N[]=new long[100000];
    M[0]=H;N[0]=1;int k=0;
    for(int i=1;i<100;i++){
      M[i]=(M[i-1]-M[i-1]%2)/2;
      N[i]=2*N[i-1];
      k=k+1;
    if(M[i]==1){break;}}
    long x=0;
    for(int j=0;j<=k;j++){
      x=x+N[j];}
    System.out.println(x);
  } H==1 H 1 {System.out.println(1);} System.out.println(1) System.out.println System.out System System.out 1 {
    long M[]=new long[100000];
    long N[]=new long[100000];
    M[0]=H;N[0]=1;int k=0;
    for(int i=1;i<100;i++){
      M[i]=(M[i-1]-M[i-1]%2)/2;
      N[i]=2*N[i-1];
      k=k+1;
    if(M[i]==1){break;}}
    long x=0;
    for(int j=0;j<=k;j++){
      x=x+N[j];}
    System.out.println(x);
  } long M[]=new long[100000]; M new long[100000] 100000 long N[]=new long[100000]; N new long[100000] 100000 M[0]=H M[0] M 0 H N[0]=1 N[0] N 0 1 int k=0; k 0 for(int i=1;i<100;i++){
      M[i]=(M[i-1]-M[i-1]%2)/2;
      N[i]=2*N[i-1];
      k=k+1;
    if(M[i]==1){break;}} int i=1; int i=1; i 1 i<100 i 100 i++ i++ i {
      M[i]=(M[i-1]-M[i-1]%2)/2;
      N[i]=2*N[i-1];
      k=k+1;
    if(M[i]==1){break;}} {
      M[i]=(M[i-1]-M[i-1]%2)/2;
      N[i]=2*N[i-1];
      k=k+1;
    if(M[i]==1){break;}} M[i]=(M[i-1]-M[i-1]%2)/2 M[i] M i (M[i-1]-M[i-1]%2)/2 (M[i-1]-M[i-1]%2) M[i-1] M i-1 i 1 M[i-1]%2 M[i-1] M i-1 i 1 2 2 N[i]=2*N[i-1] N[i] N i 2*N[i-1] 2 N[i-1] N i-1 i 1 k=k+1 k k+1 k 1 if(M[i]==1){break;} M[i]==1 M[i] M i 1 {break;} break; long x=0; x 0 for(int j=0;j<=k;j++){
      x=x+N[j];} int j=0; int j=0; j 0 j<=k j k j++ j++ j {
      x=x+N[j];} {
      x=x+N[j];} x=x+N[j] x x+N[j] x N[j] N j System.out.println(x) System.out.println System.out System System.out x String[] args args public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    long H =sc.nextLong();
    if(H==1){System.out.println(1);}
    else{
    long M[]=new long[100000];
    long N[]=new long[100000];
    M[0]=H;N[0]=1;int k=0;
    for(int i=1;i<100;i++){
      M[i]=(M[i-1]-M[i-1]%2)/2;
      N[i]=2*N[i-1];
      k=k+1;
    if(M[i]==1){break;}}
    long x=0;
    for(int j=0;j<=k;j++){
      x=x+N[j];}
    System.out.println(x);
  }}
} public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    long H =sc.nextLong();
    if(H==1){System.out.println(1);}
    else{
    long M[]=new long[100000];
    long N[]=new long[100000];
    M[0]=H;N[0]=1;int k=0;
    for(int i=1;i<100;i++){
      M[i]=(M[i-1]-M[i-1]%2)/2;
      N[i]=2*N[i-1];
      k=k+1;
    if(M[i]==1){break;}}
    long x=0;
    for(int j=0;j<=k;j++){
      x=x+N[j];}
    System.out.println(x);
  }}
} Main
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    long H =sc.nextLong();
    if(H==1){System.out.println(1);}
    else{
    long M[]=new long[100000];
    long N[]=new long[100000];
    M[0]=H;N[0]=1;int k=0;
    for(int i=1;i<100;i++){
      M[i]=(M[i-1]-M[i-1]%2)/2;
      N[i]=2*N[i-1];
      k=k+1;
    if(M[i]==1){break;}}
    long x=0;
    for(int j=0;j<=k;j++){
      x=x+N[j];}
    System.out.println(x);
  }}
}