#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int i;
	string s;
	unsigned long int n;
	while(cin>>s){
	   n=0;
	   for(i=0;s[i]!='\0';i++){ 
		  n+=(s[i]-'0')*((1<<(s.size()-i))-1);
		  if(s[i]=='2') break;
       }
       cout<<n<<endl;
    }       
}