#include<cstdio>
#include<cmath>
using namespace std;
int main(){
	char num[100];
	while (scanf("%s", &num) != EOF){
		long long sum = 0;
		int x = 0;
		for (int i = 0; num[i] != '\0'; i++){
			x++;
		}
		int y = x;
		for (int i = 0; i < y; i++){
			if (num[i] == '2'){
				sum = sum + 2 * (pow(2, x) - 1);
				break;
			}
			else if (num[i] == '1'){
				sum = sum + pow(2, x) - 1;
				x--;
			}
			else{
				x--;
			}
		}
		if (sum == 0){
			break;
		}
		else{
			printf("%lld\n", sum);
		}
	}
}