1. 

/**
* FWP: Ausgewaehlte Probleme aus dem ACM (SS10)
*
* Method: Math: Bases
* Problem: 575 - SkewBinary
* Accepted: 0.084
* @author Evgeni Pavlidis
*
*/
import java.io.*;
import java.util.*;

class Main {

public static void main(String...args) throws Exception
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String input;



while( !(input = reader.readLine()).equals("0") )
{
input = new StringBuffer(input).reverse().toString();
int n = 0;
int mask = 1;
int offset = 0;


for(int i = 0; i < input.length(); i++)
{
mask = mask << 1;
if(input.charAt(i) == '1')
{
n |= mask;
offset++;
}
else if(input.charAt(i) == '2')
{
n |= mask;
offset -= mask - 2;
}
//System.out.println(n + " " + offset);
}
System.out.println(n-offset);

}
}
}