Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."

<image>

The problem is: 

You are given a lucky number n. Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

If we sort all lucky numbers in increasing order, what's the 1-based index of n? 

Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back.

Input

The first and only line of input contains a lucky number n (1 ≤ n ≤ 109).

Output

Print the index of n among all lucky numbers.

Examples

Input

4


Output

1


Input

7


Output

2


Input

77


Output

6
'''
    Get the number n and turn it into a list l of its digits.
'''
n = int(input())
l = list(int(i) for i in str(n))

def index_of(l):
    idx = 0
    zero = [0 for i in range(len(l))]
    # We turn a digit into 0 when we change to a lucky number with fewer 
    # digits.
    while l != zero:
        # We run through the digits starting from right to left turning 7's into 
        # 4's and 4's into 7's (and when we turn 4's into 7's it's a bit more 
        # complicated because you have to change the next digit to something)
        for i in range(len(l) - 1, -1, -1): 
            if l[i] == 0:
                break
            # hard case
            elif l[i] == 4:
                # When the current digit is 4, we change it into 0 if:
                #   the digit 4 is the leftmost digit, for example if l is 
                #   [4, 4], the next lucky number is [0, 7] and the series of 
                #   changes we do is [4, 4] -> [4, 7] -> [0, 7].
                #
                #   the digit to the left of 4 is 0, for example if l is 
                #   [0, 4, 4], the next lucky number would be [0, 0, 7] and the 
                #   series of changes we do is [0, 4, 4] -> [0, 4, 7] -> 
                #   [0, 0, 7].
                #
                # Note that it is important that we put i == 0 as our first 
                # condition as otherwise it's possible that i - 1 < 0.
                if i == 0 or l[i - 1] == 0:
                    l[i] = 0
                else:
                    l[i] = 7
            # easy case
            elif l[i] == 7:
                l[i] = 4
                break
        idx += 1
    return idx

print(index_of(l))
				 		 		    	 	  	    	     	