import java.io.*;
import java.util.*;

public class danger
{
		public static void main(String[] args)
				throws Exception
		{
				BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
				String s;
				while ((s = in.readLine()) != null) {
						int n = (int) Double.parseDouble(s);
						if (n == 0)
								break;
						int r = 0;
						int e = 2;
						while (n > 1) {
								if ((n & 1) > 0) {
										r += e;
								}
								e *= 2;
								n >>= 1;
						}
						System.out.println(r + 1);
				}
		}
}
