#include <iostream>
#include <string>
using namespace std;
typedef long long LL;
const int DP_Max=20;
LL dp[DP_Max][3][2];
/*
* 0 含有1的个数
* 1 数的总个数
*/
LL DP_bit(const string& str)
{
memset(dp,0,sizeof(dp));
dp[0][1][1]=1;
const int strLen=str.length();
for ( int i=1 ; i<=strLen ;++i ){
//未达到上界
dp[i][0][0]=dp[i-1][1][0]+dp[i-1][0][0]*10;
dp[i][1][0]=dp[i-1][1][0]*10;
//上一位达到上界
for (int j = 0; j < str[i-1]-'0'; ++j){
dp[i][1][0]+=dp[i-1][1][1];
dp[i][0][0]+=dp[i-1][0][1];
if ( j==1 ){
dp[i][0][0]+=dp[i-1][1][1];
}
}
//都为上界
dp[i][1][1]+=dp[i-1][1][1];
dp[i][0][1]+=dp[i-1][0][1];
if ( str[i-1]=='1' ){
dp[i][0][1]+=dp[i-1][1][1];
}
}
//cout<<dp[strLen][0][1]<<endl;
//cout<<dp[strLen][1][1]<<endl;
return dp[strLen][0][0]+dp[strLen][0][1];
}
int main()
{
string str;
while ( true ){
cin>>str;
cout<<DP_bit(str)<<endl;
if ( str=="0" ){
break;
}
}
return 0;
}