/* package whatever; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		
		f623("111");
		f623("1110");
		f623("101100");
	}
	
	/**
	 * 1のビットがN個ある二進表記文字列が与えられたとき、
	 * 次に大きい1のビットがN個ある二進表記文字列を求める。
	 * @param s 1のビットがN個ある二進表記文字列
	 * @return 次に大きい1のビットがN個ある二進表記文字列
	 */
	static String f623(String s) {
		List<String> list = new ArrayList<String>(s.length());
		int n = 0;
		for (int i = 0; i < s.length(); i++) {
			int j = (s.length() - 1) - i;
			if (s.regionMatches(j, "1", 0, 1)) {
				list.add(i, "1"); // リテラル(コンスタントプール)を入れるので
				n++;
			} else if (s.regionMatches(j, "0", 0, 1)) {
				list.add(i, "0");
			} else {
				throw new IllegalArgumentException(s);
			}
		}
		
		if (n == 0) {
			throw new IllegalArgumentException(s);
		}
		
		int c = 0;
		while (c != n) {
			int d = 1;
			c = 0;
			for (int i = 0; i < list.size(); i++) {
				if (d == 0) {
					if ("1" == list.get(i)) { // equals()使わなくてOK
						c++;
						if (c > 3) {
							break;
						}
					}
				} else {
					if ("1" == list.get(i)) {
						list.set(i, "0");
					} else {
						list.set(i, "1");
						d = 0;
						c++;
					}
				}
			}
			if (d == 1) {
				list.add("1");
			}
		}
		
		StringBuilder dest = new StringBuilder(list.size());
		for (String p : list) {
			dest.append(p);
		}
		String result = dest.reverse().toString();
		System.out.println(s + " -> " + result);
		return result;
	}
}