import java.util.*;
import java.io.*;

public class Lol3
{
    public static long awesomeness (long num)
    {
	String omg = "0" + Long.toBinaryString (num);
	String wtf = "";
	for (int x = 0 ; x < omg.length () ; x++)
	{
	    wtf = omg.charAt (x) + wtf;
	}
	wtf = wtf.replaceFirst ("10", "01");
	long weight = 0l;
	omg = "";
	for (int x = 0 ; x < wtf.length () ; x++)
	{
	    omg = wtf.charAt (x) + omg;
	}
	for (int x = 0 ; x < omg.length () ; x++)
	{
	    if (omg.charAt (x) == '1')
	    {
		weight += (int) Math.pow (2, omg.length () - (1 + x));
	    }
	}
	return weight;
    }


    public static void main (String[] args) throws IOException
    {
	BufferedReader in = new BufferedReader (new FileReader ("DATA3.txt"));
	PrintWriter out = new PrintWriter (new FileWriter ("OUT3.txt"));
	for (int asd = 0 ; asd < 5 ; asd++)
	{
	    out.println (awesomeness (Long.parseLong (in.readLine ())));
	    out.flush ();
	}
	out.close ();
    }
}



