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.util.*;

public class Main {
	public static int MOD;
	public static int[][][] f;
	public static int[] arr;
	public static int n;
	public static Map<Integer, String> map =new HashMap<Integer, String>();
	public static PriorityQueue<Integer> q = new PriorityQueue<Integer>();
	public static void main(String[] args) throws Exception
	{
		MyScanner input = new MyScanner();
		BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
		//init();
		int n = input.nextInt();
		Integer[] arr = new Integer[init().size()]; 
		init().toArray(arr);
		Arrays.sort(arr);
		
		System.out.println(binarySearch(arr, n) +1);

	}

	public static int binarySearch(Integer[] arr, int num)
	{
		int ind = arr.length - 1;
		int a = 0;
		int b = arr.length-1;
		while(a <= b && a >= 0 && b >= 0)
		{
			int mid = (a+b)/2;
			if(arr[mid] > num)
				b = mid -1;
			else if(arr[mid] < num)
				a = mid +1;
			else
				return mid;
		}
		return -1;
	}
	public static ArrayList<Integer> init()
	{
		ArrayList<Integer> arr = new ArrayList<Integer>();
		arr.add(new Integer(4));
		arr.add(new Integer(7));
		
		int ind = 0;
		StringBuilder s = new StringBuilder();
		while(s.length() <= 8)
		{
			arr.add( new Integer(arr.get(ind).toString() + "4" ));
			arr.add( new Integer( arr.get(ind).toString() + "7"));
			ind ++;
			s = new StringBuilder(arr.get(ind).toString());
		}
		return arr;
	}


private static class MyScanner 
{
	BufferedReader br;
	StringTokenizer st;

	public MyScanner(String s) 
	{

		try
		{
			br = new BufferedReader(new FileReader(s));
		} catch (IOException e)
		{
			e.printStackTrace();
		}

	}

	public MyScanner() 
	{
		br = new BufferedReader(new InputStreamReader(System.in));
		st = new StringTokenizer("");
	}

	public String next() 
	{
		if (st == null || !st.hasMoreElements()) 
		{
			try 
			{
				String line = br.readLine();
				if (line == null) {
					throw new UnknownError();
				}
				while (line.trim().equals("")) {
					line = br.readLine();
					if (line == null) {
						throw new UnknownError();
					}
				}
				st = new StringTokenizer(line);
			} 
			catch (IOException e) 
			{
				throw new UnknownError();
			}
		}
		return st.nextToken();
	}

	public String nextLine() {
		try {
			String line = br.readLine();
			if (line == null) {
				throw new UnknownError();
			}
			return line;
		}
		catch (IOException e) {
			throw new UnknownError();
		}
	}

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

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

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

}
}