import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        long H = sc.nextLong();
        long a = 2 * H;
        long ans = 0;

        for(long i=1; i<a; i*=2){
            if(H>1){
                ans += i;
                H = H / 2;
            }
            else if(H==1){
                ans += i;
                break;
            }
        }
        System.out.println(ans);
    }
} import java.util.*; util.* java public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        long H = sc.nextLong();
        long a = 2 * H;
        long ans = 0;

        for(long i=1; i<a; i*=2){
            if(H>1){
                ans += i;
                H = H / 2;
            }
            else if(H==1){
                ans += i;
                break;
            }
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        long H = sc.nextLong();
        long a = 2 * H;
        long ans = 0;

        for(long i=1; i<a; i*=2){
            if(H>1){
                ans += i;
                H = H / 2;
            }
            else if(H==1){
                ans += i;
                break;
            }
        }
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);

        long H = sc.nextLong();
        long a = 2 * H;
        long ans = 0;

        for(long i=1; i<a; i*=2){
            if(H>1){
                ans += i;
                H = H / 2;
            }
            else if(H==1){
                ans += i;
                break;
            }
        }
        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long H = sc.nextLong(); H sc.nextLong() sc.nextLong sc long a = 2 * H; a 2 * H 2 H long ans = 0; ans 0 for(long i=1; i<a; i*=2){
            if(H>1){
                ans += i;
                H = H / 2;
            }
            else if(H==1){
                ans += i;
                break;
            }
        } long i=1; long i=1; i 1 i<a i a i*=2 i*=2 i 2 {
            if(H>1){
                ans += i;
                H = H / 2;
            }
            else if(H==1){
                ans += i;
                break;
            }
        } {
            if(H>1){
                ans += i;
                H = H / 2;
            }
            else if(H==1){
                ans += i;
                break;
            }
        } if(H>1){
                ans += i;
                H = H / 2;
            }
            else if(H==1){
                ans += i;
                break;
            } H>1 H 1 {
                ans += i;
                H = H / 2;
            } ans += i ans i H = H / 2 H H / 2 H 2 if(H==1){
                ans += i;
                break;
            } H==1 H 1 {
                ans += i;
                break;
            } ans += i ans i break; System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        long H = sc.nextLong();
        long a = 2 * H;
        long ans = 0;

        for(long i=1; i<a; i*=2){
            if(H>1){
                ans += i;
                H = H / 2;
            }
            else if(H==1){
                ans += i;
                break;
            }
        }
        System.out.println(ans);
    }
} public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        long H = sc.nextLong();
        long a = 2 * H;
        long ans = 0;

        for(long i=1; i<a; i*=2){
            if(H>1){
                ans += i;
                H = H / 2;
            }
            else if(H==1){
                ans += i;
                break;
            }
        }
        System.out.println(ans);
    }
} Main
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        long H = sc.nextLong();
        long a = 2 * H;
        long ans = 0;

        for(long i=1; i<a; i*=2){
            if(H>1){
                ans += i;
                H = H / 2;
            }
            else if(H==1){
                ans += i;
                break;
            }
        }
        System.out.println(ans);
    }
}