#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

//返回2的i次方
int pow(int i) {
	int res = 1;
	while (i != 0) {
		res *= 2;
		i--;
	}
	return res;
}
int skew(string s) {
	int res = 0;
	reverse(s.begin(), s.end());
	for (int i = 0; i < s.size(); i++) {
		res += (s[i]-'0') * (pow(i + 1) - 1);
	}
	return res;
}
int main() {
	//cout << pow(10) << endl;
	string s;
	while (cin >> s) {
		if (s == "0")break;
		cout << skew(s) << endl;
	}
	return 0;
}