import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextInt()) {
            int n = sc.nextInt();
            int ans = 1;
            n += 1;
            while(ans <= n) {
                ans <<= 1;
            }
            System.out.println((ans >> 1) - 1);
        }
    }
}