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.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
    public static void main(String[] argv) {
        MainRun mainSolve = new MainRun();
        mainSolve.run(0, 0);
    }
}

class Task {
	TreeSet <Long> st;
	long getNum(int mass[]) {
		long res = 0;
		for (int i = 1; i < 12; i++) {
			if (mass[i] == 0)
				break;
			res = res * 10L + mass[i];
		}
		return res;
	}
	void rec(int pos, int mass[]) {
		if (pos > 11) {
			st.add(getNum(mass));
			return;
		}
		mass[pos] = 0;
		rec(pos + 1, mass);
		mass[pos] = 4;
		rec(pos + 1, mass);
		mass[pos] = 0;
		mass[pos] = 7;
		rec(pos + 1, mass);
		mass[pos] = 0;
	}
	public void solve(InputReader in, PrintWriter out) {
		int n = in.nextInt();
		int len = 0;
		int temp = n;
		while (temp != 0) {
			len++;
			temp /= 10;
		}
		int dl[] = new int[14];
		st = new TreeSet<Long>();
		rec(1, dl);

		int num = 1;
		Iterator it = st.iterator();
		while (it.hasNext()) {
			long value = (long)it.next();
			if (value == n) {
				out.println(num - 1);
				return;
			}
			num++;
		}
	}
}

class MainRun {
	void run(int inF, int outF) {
//		inF = outF = 0;
		String input = "input.txt";
//		String input = "large.in";	
		String output = "output.txt";
//		String output = "puzzle-2048.out";
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in;
		PrintWriter out;
		if (inF == 1)	
			in = new InputReader(input);
		else
			in = new InputReader(inputStream);
		if (outF == 1)
			out = getPrintWriter(output);
		else
			out = getPrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(in, out);
		out.close();
	}
	public static PrintWriter getPrintWriter(OutputStream stream) {
		return new PrintWriter(stream);
	}
	public static PrintWriter getPrintWriter(String f) {
		try {
			return new PrintWriter(new File(f));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		return null;
	}	
}

class InputReader {
	BufferedReader reader;
	StringTokenizer tokenizer;
	InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream));
		tokenizer = null;
	}
	InputReader(String f) {
		try {
			reader = new BufferedReader(new FileReader(f));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		tokenizer = null;		
	}
	public String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch(IOException e) {
				throw new RuntimeException(e);
			} catch(NullPointerException e) {
				return "";
			}
		}
		return tokenizer.nextToken();
	}
	public String getLine() {
		try {
			return (String)reader.readLine();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "";
	}	
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public char nextChar() {
		return next().charAt(0);
	}	
	public long nextLong() {
		return Long.parseLong(next());
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
	public int[] nextIntArray(int n) {
		int a[] = new int[n + 2];
		for (int i = 1; i <= n; i++)
			a[i] = nextInt();
		return a;
	}
}