# include <cstdio>
# include <cstring>
# include <iostream>
using namespace std;
int mul [15],a[15];
int main (void)
{
	int n;
	mul[0]=1;	
	for (int i=1;i<=10;i++)
		mul[i]=mul[i-1]*4;
	while (cin>>n)
	{
		int ans=0,len=0;
		while (n)
		{
			a[++len]=n%10;
			n/=10;
		}
		for (int i=len;i>=1;i--)
		{
			if (a[i]>3)
			{
				ans+=mul[i-1]*3;
				break;
			}
			if (i>1)
				ans+=a[i]*mul[i-2]*3;
			else ans+=min(a[i],3);
		}
		cout<<ans<<endl;
	}
	return 0;
}