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.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class Solution {

//	public static final double EPS = 1e-9;
	public static final int MOD = 1000000007;
//	public static final double PI = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679;
//	public static final int DX[] = {1, -1, 0, 0};
//	public static final int DYy[] = {0, 0, 1, -1};
//	public final int sievesize = (int) (1e6);
//	public boolean[] prime;

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		
		public void solve(int testNumber, InputReader in, OutputWriter out) throws IOException {
			int n = in.nextInt();
			ArrayList<String> arr = new ArrayList<>();
			ArrayList<Integer> f = new ArrayList<>();
			arr.add("4");
			arr.add("7");
			f.add(4);
			f.add(7);
			while(true) {
				Collections.sort(f);
				if (f.contains(n)) {
					out.println(f.indexOf(n) + 1);
					return;
				}
				ArrayList<String> temp = (ArrayList<String>) arr.clone();
				arr.clear();
				for (int i = 0; i < temp.size(); i++) {
					arr.add("4" + temp.get(i));
					f.add(Integer.parseInt(arr.get(arr.size() - 1)));
					arr.add("7" + temp.get(i));
					f.add(Integer.parseInt(arr.get(arr.size() - 1)));
				}
			}
		}

//		static class Node {
//			String name;
//			LinkedList<Node> list;
//			
//			public Node(String name) {
//				this.name = name;
//				list = new LinkedList<>();
//			}
//		}
//        
//		static class Pair<T> {   	
//	      	T first, second;
//		        	
//		    public Pair(T first, T second) {
//	    		this.first = first;
//				this.second = second;
//			}
//	    }
		
	}
	
//	public static void sieve(){
//		prime = new boolean[sievesize + 1];
//		Arrays.fill(prime, true);
//	    for(int x = 2; x * x < sievesize; x++)
//	    { 
//	    	if(prime[x])
//	    		for(int y = x * 2; y < sievesize; y += x) 
//	    			prime[y] = false; 
//	    }
//	}

//	public static int[] shuffle(int arr[], Random gen) {
//		for (int i = arr.length - 1; i > 0; i--) {
//            int index = gen.nextInt(i + 1);
//            int temp = arr[index];
//            arr[index] = arr[i];
//            arr[i] = temp;
//        }
//		return arr;
//	}
	
//	public static boolean triangle(long a, long b, long c){
//	    return ((a+b) > c && (b+c) >a && (a+c) > b);
//	}
	
//	public static boolean isPerfectSquare(long n){
//		if (n < 0) 
//	    	return false;
//	    long test = (long) (Math.sqrt(n) + 0.5);
//	    return test*test == n;
//	}
	
//	public static int isnum(char s){
//		if(s=='1' || s=='2' || s=='3' || s=='4' || s=='5' || s=='6' || s=='7' || s=='8' || s=='9' || s=='0') 
//	    	return 1; 
//		return 0;
//	}
	
//	public static long nextPowerOf2(long n){
//	    n--;
//	    n |= n >> 1;
//	    n |= n >> 2;
//	    n |= n >> 4;
//	    n |= n >> 8;
//	    n |= n >> 16;
//	    n++;
//	    return n;
//	}
	
//	public static int gcd(int a, int b){
//	    int t; 
//	    while (b > 0){ 
//	    	a = a % b; 
//	    	t = a; 
//	    	a = b; 
//	    	b = t; 
//    	}
//	    return a;
//	}
	
//	public static int findGcdArray(int[] arr) {
//		int min = Integer.MAX_VALUE;
//		for (int i = 0; i < arr.length; i++)
//			min = Math.min(min, arr[i]);
//		while (min > 1) {
//			int i = 0, s = 0;
//			while (i < arr.length) {
//				s += arr[i] % min;
//				i++;
//			}
//			if (s == 0) return min;
//			min--;
//		}
//		return 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 char nextChar() {
			return next().charAt(0);
		}
		
		public float nextFloat() {
			return Float.parseFloat(next());
		}
		
		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int size) {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			int[] arr=new int[size];
			for(int i = 0; i < size; i++) 
				arr[i] = Integer.parseInt(tokenizer.nextToken());
			return arr;
		}

		public long[] nextLongArray(int size) {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			long[] arr=new long[size];
			for(int i = 0; i < size; i++) 
				arr[i] = Long.parseLong(tokenizer.nextToken());
			return arr;
		}
		
		public float[] nextFloatArray(int size) {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			float[] arr=new float[size];
			for(int i = 0; i < size; i++) 
				arr[i] = Float.parseFloat(tokenizer.nextToken());
			return arr;
		}

		public double[] nextDoubleArray(int size) {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			double[] arr=new double[size];
			for(int i = 0; i < size; i++) 
				arr[i] = Double.parseDouble(tokenizer.nextToken());
			return arr;
		}

		public String[] nextStringArray(int size) throws IOException {
			String[] arr=new String[size];
			for(int i = 0; i < size; i++) 
				arr[i] = reader.readLine();
			return arr;
		}

		public char[] nextCharArray(int size) throws IOException {
			return reader.readLine().toCharArray();
		}
	}

	static class OutputWriter {
		public PrintWriter pw;

		public OutputWriter(OutputStream stream) {
			pw = new PrintWriter(stream);
		}
		
		public void println() {
			pw.println();
		}

		public void println(Object str) {
			pw.println(str);
		}

		public void print(Object str) {
			pw.print(str + " ");
		}

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

		public void flush() {
			pw.flush();
		}

		public void printStringArray(String[] arr) {
			for(int i = 0; i < arr.length; i++)
				pw.println(arr[i]);
		}

		public void printIntArray(int[] arr) {
			for(int i = 0; i < arr.length; i++)
				pw.print(arr[i] + " ");
		}

		public void printLongArray(long[] arr) {
			for(int i = 0; i < arr.length; i++)
				pw.print(arr[i] + " ");
		}

		public void printCharArray(char[] arr) {
			for(int i = 0; i < arr.length; i++)
				pw.print(arr[i] + " ");
		}

		public void printFloatArray(float[] arr) {
			for(int i = 0; i < arr.length; i++)
				pw.print(arr[i] + " ");
		}

		public void printDoubleArray(double[] arr) {
			for(int i = 0; i < arr.length; i++)
				pw.print(arr[i] + " ");
		}
	}
}