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
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    public static void main (String[] args) {
        FastReader in = new FastReader(System.in);

        int n = in.nextInt();

        int d = 0;
        int b = 0;

        while (n != 0) {
            b = b | (n % 10 == 7 ? 1 : 0) << d;

            d++;
            n /= 10;
        }

        System.out.println((long) Math.pow(2, d) - 1 + b);
    }
}

class FastReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public FastReader(InputStream stream) {
        this.reader = new BufferedReader(new InputStreamReader(stream));
        this.tokenizer = new StringTokenizer("");
    }

    public boolean hasNext() {
        return ensureTokens();
    }

    public String next() {
        return  ensureTokens() ? tokenizer.nextToken() : null;
    }

    private boolean ensureTokens() {
        while(!tokenizer.hasMoreTokens()){
            try{
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (Exception e){
                return false;
            }
        }
        return true;
    }

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (Exception e) {
            return null;
        }
    }

    public char[] nextCharArray() {
        return nextLine().toCharArray();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public int[] nextIntArray(int size) {
        int[] array = new int[size];
        for (int i = 0; i < size; i++) {
            array[i] = nextInt();
        }
        return array;
    }

    public int[] nextIntArrayOnLine() {
        String line = nextLine();
        String[] tokens = line.split(" ");
        int[] array = new int[tokens.length];
        for (int i = 0; i < tokens.length; i++) {
            array[i] = Integer.parseInt(tokens[i]);
        }
        return array;
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public long[] nextLongArray(int size) {
        long[] array = new long[size];
        for (int i = 0; i < size; i++) {
            array[i] = nextLong();
        }
        return array;
    }

    public float nextFloat() {
        return Float.parseFloat(next());
    }

    public float[] nextFloatArray(int size) {
        float[] array = new float[size];
        for (int i = 0; i < size; i++) {
            array[i] = nextFloat();
        }
        return array;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

    public double[] nextDoubleArray(int size) {
        double[] array = new double[size];
        for (int i = 0; i < size; i++) {
            array[i] = nextDouble();
        }
        return array;
    }

    public short nextShort() {
        return Short.parseShort(next());
    }

    public short[] nextShortArray(int size) {
        short[] array = new short[size];
        for (int i = 0; i < size; i++) {
            array[i] = nextShort();
        }
        return array;
    }

    public BigDecimal nextBigDecimal() {
        return new BigDecimal(next());
    }

    public BigInteger nextBigInteger() {
        return new BigInteger(next());
    }
}

class FastWriter {
    private final PrintWriter printWriter;

    public FastWriter(OutputStream stream) {
        printWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream)));
    }

    public FastWriter(Writer writer) {
        printWriter = new PrintWriter(writer);
    }

    public void close() {
        printWriter.close();
    }

    public void print(boolean element) {
        printWriter.print(element);
    }

    public void print(char[] element) {
        printWriter.print(element);
    }

    public void print(double element) {
        printWriter.print(element);
    }

    public void print(float element) {
        printWriter.print(element);
    }

    public void print(int element) {
        printWriter.print(element);
    }

    public void print(long element) {
        printWriter.print(element);
    }

    public void print(String element) {
        printWriter.print(element);
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0) {
                printWriter.print(' ');
            }
            printWriter.print(objects[i]);
        }
    }

    public void println(boolean element) {
        printWriter.println(element);
    }

    public void println(char[] element) {
        printWriter.println(element);
    }

    public void println(double element) {
        printWriter.println(element);
    }

    public void println(float element) {
        printWriter.println(element);
    }

    public void println(int element) {
        printWriter.println(element);
    }

    public void println(long element) {
        printWriter.println(element);
    }

    public void println(String element) {
        printWriter.println(element);
    }

    public void println() {
        printWriter.println();
    }

    public void println(Object... objects) {
        print(objects);
        printWriter.println();
    }

    public void printf(String format, Object... args) {
        printWriter.printf(format, args);
    }
}

