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.awt.Point;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import sun.misc.Queue;

/**
 *
 * @author Mojtaba
 */
public class Main {

    public static void main(String[] args) throws IOException, InterruptedException {
        MojtabaKhooryaniScanner in = new MojtabaKhooryaniScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);
        StringBuilder sb = new StringBuilder("");

        ArrayList<Long> list = new ArrayList<>();
        list.add(4L);
        list.add(7L);
        ArrayList<Long> number = (getSequenceNumbers(list, 10));
        Collections.sort(number);
        long a = in.nextInt();
        sb.append(number.indexOf(a) + 1);

        writer.println(sb.toString());
        writer.close();
        in.close();
    }

    static ArrayList<Long> getSequenceNumbers(ArrayList<Long> list, int maxDigits) {
        ArrayList<Long> numbers = new ArrayList<>(list);
        int lastBegin = -1;
        for (int dig = 1; dig < maxDigits; dig++) {
            int begin = numbers.size() - 1;
            for (int i = 0; i < list.size(); i++) {
                for (int j = begin; j > lastBegin; j--) {
                    long newNumber = numbers.get(j) * 10 + list.get(i);
                    numbers.add(newNumber);
                }
            }
            lastBegin = begin;
        }
        return numbers;
    }
}

class MojtabaKhooryaniScanner {

    BufferedReader reader;
    StringTokenizer tokenizer;

    public MojtabaKhooryaniScanner(InputStream stream) {
        this.reader = new BufferedReader(new InputStreamReader(stream));
    }

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

    public int[] nextIntegerArray(int n) throws IOException {
        int[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    public long[] nextLongArray(int n) throws IOException {
        long[] a = new long[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = nextLong();
        }
        return a;
    }

    public int nextInt(int radix) throws IOException {
        return Integer.parseInt(next(), radix);
    }

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

    public long nextLong(int radix) throws IOException {
        return Long.parseLong(next(), radix);
    }

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

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

    public BigInteger nextBigInteger(int radix) throws IOException {
        return new BigInteger(next(), radix);
    }

    public String next() throws IOException {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
            return this.next();
        }
        return tokenizer.nextToken();
    }

    public void close() throws IOException {
        this.reader.close();
    }
}
