// Arup Guha
// 3/5/2019
// Solution to 2019 Mercer Programming Contest Problem 4: Fake Binaries

import java.util.*;
import java.math.*;

public class fakebinaries {
	
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		String line = stdin.next();
		
		// Process cases.
		while (!line.equals("-1")) {
			
			// Store as digits.
			int n = line.length();
			int[] digits = new int[n];
			boolean flag = false;
			
			// Read in but set to equivalent binary number. 
			// After first number > 1, make everything 1.
			for (int i=0; i<n; i++) {
				digits[i] = line.charAt(i) - '0';
				if (digits[i] > 1) flag = true;
				if (flag) digits[i] = 1;
			}
			
			// Each slot is a placeholder for how many times 1 appears in that slot
			// in the sum.
			int[] res = new int[n];
			int curNum = 0;
			
			for (int i=n-1; i>=0; i--) {
				
				// No change occurs for 0s.
				if (digits[i] == 0) continue;
					
				// For putting 0 in digit i.
				for (int j=i+1; j<n; j++) res[j] += (1<<(n-2-i));  
					
				// How many times we can place 1 in slot i.
				res[i] = curNum+1;
					
				// Now update total number of solutions.
				curNum += (1<<(n-1-i));
			}
			
			BigInteger ten = new BigInteger("10");
			BigInteger ans = new BigInteger("0");
			BigInteger pow10 = new BigInteger("1");
			
			// Now add everything up.
			for (int i=n-1; i>=0; i--) {
				
				// This is the meaning of each digit.
				BigInteger tmp = new BigInteger(""+res[i]);
				tmp = tmp.multiply(pow10);
				
				// Add and update pow 10.
				ans = ans.add(tmp);
				pow10 = pow10.multiply(ten);
			}
			
			// Ta da!
			System.out.println(ans);
			
			// Get next case.
			line = stdin.next();
		}
	}
}
