import java.io.*;
import java.util.*;
import java.lang.*;
public class D2 {
	public static void main(String[] args) throws IOException{

		Scanner in = new Scanner (new File("DATA2.txt"));
		PrintWriter p = new PrintWriter ("OUT2.txt");
		String str ;
		int num = 0;
		int count = 0;
		int count2 = 0;
		int x = 1,a2,a1;
		for(int c = 0; c < 5; c++)
		{	count = 0;
			str=in.nextLine();
			StringTokenizer st = new StringTokenizer (str);
			String a = st.nextToken();
			int b=Integer.parseInt(a);
			a1 = b;
			while(a1>0)
			{
				for(int i = 0;Math.pow(2,i)<=a1;i++)
				{
					num = i;
					
				}

				a1 = (int)(a1 - Math.pow(2, num));
				count++;
			}
			while(count2 != count)
			{count2 = 0;
				a2 = b + x;
				while(a2>0){
					for(int i = 0;Math.pow(2,i)<=a2;i++)
					{
						num = i;
					}

					a2 = (int)(a2 - Math.pow(2, num));
					count2++;
				}
			}p.println(b+x-1);x = 1;
		}
		in.close();
		p.close();
	}
}

