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

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Administrator
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

//codeforce
public class Main {

    private static BufferedReader in;
    private static PrintWriter out;
    private static StringTokenizer input;

    public static void main(String[] args) throws IOException {
        // -------------------------------------------------------------------------
        // Initializing...
        new Main();
        // -------------------------------------------------------------------------
        // put your code here... :)

        String number = nextString();
        int lengthNumber=number.length();
        int result=0;
        for (int i = 0; i < lengthNumber-1; i++) {
            result+=Math.pow(2, i+1);
        }
        String binaryNumber="";
        for (int i = 0; i < number.length(); i++) {
            if(number.charAt(i)=='4'){
                binaryNumber+="0";
            }else{
                // current number if 7
                binaryNumber+="1";              
            }
        }
        System.out.println(result+Integer.parseInt(binaryNumber,2)+1);
        // writeln("");
        // -------------------------------------------------------------------------
        // closing up
        end();
        // --------------------------------------------------------------------------

    }

    public Main() throws IOException {
        // Input Output for Console to be used for trying the test samples of
        // the problem
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        // -------------------------------------------------------------------------
        // Initalize Stringtokenizer input
        input = new StringTokenizer(in.readLine());
    }

    private static int nextInt() throws IOException {
        if (!input.hasMoreTokens())
            input = new StringTokenizer(in.readLine());
        return Integer.parseInt(input.nextToken());
    }

    private static long nextLong() throws IOException {
        if (!input.hasMoreTokens())
            input = new StringTokenizer(in.readLine());
        return Long.parseLong(input.nextToken());
    }

    private static double nextDouble() throws IOException {
        if (!input.hasMoreTokens())
            input = new StringTokenizer(in.readLine());
        return Double.parseDouble(input.nextToken());
    }

    private static String nextString() throws IOException {
        if (!input.hasMoreTokens())
            input = new StringTokenizer(in.readLine());
        return input.nextToken();
    }

    private static void write(String output) {
        out.write(output);
        out.flush();
    }

    private static void writeln(String output) {
        out.write(output + "\n");
        out.flush();
    }

    private static void end() throws IOException {
        in.close();
        out.close();
        System.exit(0);
    }

}
