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

public class Main {
    //---------------------------------------------------------------------------

    public static void main(String[] args) throws Exception {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        //-----------------------------------------------------------------------
        char[] a = in.nextCharArray();
        int n = a.length;
        long ans = 0;
        for (int i = 0; i < n; i++) {
            ans += (long)Math.pow(2, i);
        }
        for (int i = n - 1; i >= 0; i--) {
            if (a[i] == '7') {
                ans += (long)Math.pow(2, n - 1 - i);
            }
        }
        out.println(ans);
        //-----------------------------------------------------------------------
        out.close();
    }

    //---------------------------------------------------------------------------
    static void shuffleArray(int[] ar) {
        Random rnd = ThreadLocalRandom.current();
        for (int i = ar.length - 1; i > 0; i--) {
            int index = rnd.nextInt(i + 1);
            int a = ar[index];
            ar[index] = ar[i];
            ar[i] = a;
        }
    }

    static class Pair<F, S> implements Comparable<Pair<F, S>> {

        F first;
        S second;

        public Pair() {

        }

        public Pair(F f, S s) {
            this.first = f;
            this.second = s;
        }

        @Override public boolean equals(Object o) {
            Pair<F, S> p = (Pair<F, S>) o;
            if (first.equals(p.first) && second.equals(p.second)) {
                return true;
            }
            return false;
        }

        public int compareTo(Pair<F, S> p) {
            int ret = ((Comparable<F>) first).compareTo(p.first);
            if (ret == 0) {
                ret = ((Comparable<S>) second).compareTo(p.second);
            }
            return ret;
        }
    }

    static class BitMask {
        private int mask;

        public BitMask() {
            mask = 0;
        }

        public BitMask(BitMask b) {
            mask = b.getMask();
        }

        public BitMask(int i) {
            mask = i;
        }

        public int getMask() {
            return mask;
        }

        public void setMask(int i) {
            mask = i;
        }

        public int get(int i) {
            return (mask >> i) & 1;
        }

        public void set(int i, int v) {
            if (v == 0) {
                mask = mask & ~(1 << i);
            } else {
                mask = mask | (1 << i);
            }
        }

        public void set(int v) {
            for (int i = 0; i < 32; i++) {
                set(i, v);
            }
        }

        public void flip(int i) {
            mask = mask ^ (1 << i);
        }

        public void flip() {
            for (int i = 0; i < 31; i++) {
                flip(i);
            }
        }

        public int count() {
            int ret = 0;
            for (int i = 0; i < 32; i++) {
                if (get(i) == 1) {
                    ret++;
                }
            }
            return ret;
        }

        public static int grayCode(int i) {
            return i ^ (i >> 1);
        }
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

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

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

        public boolean hasNext() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    String s = reader.readLine();
                    if (s == null) {
                        return false;
                    }
                    tokenizer = new StringTokenizer(s);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return true;
        }

        public void skipLine() {
            try {
                tokenizer = null;
                reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}