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.ByteArrayInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class round299b {
	public static void main(String[] args) {
		InputStream inputStream; 
		if (true)
			inputStream = System.in;			
		else
		{
			String str = "444";
			inputStream = new ByteArrayInputStream(str.getBytes(StandardCharsets.UTF_8));
		}
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}

}

class TaskA{
	public void solve(int n, InputReader in, PrintWriter out){
		String[] strs = {"zero", "one", "two", "three", "four", "five",
				"six", "seven", "eight", "nine", "ten", 
				"eleven", "twelve", "thirteen", "fourteen", "fifteen",
				"sixteen", "seventeen", "eighteen", "nineteen"};
		String[] strs2 = {"", "", "twenty", "thirty", "forty", "fifty",
				"sixty", "seventy", "eighty", "ninety"};
		
		int nr = in.nextInt();
		if(nr<20)
			out.print(strs[nr]);
		else
		{
			int x = nr/10;
			int y = nr%10;
			if (y>0)
				out.println(strs2[x]+"-"+strs[y]);
			else
				out.println(strs2[x]);
		}
	}
}
class TaskB{
	public void solve(int n, InputReader in, PrintWriter out){
		long nr = in.nextLong();
		long two = 1;
		long index = 0;	
		
		while(nr>0){			
			if (nr%10==7)
				index = index + two;			
			nr = nr/10;
			two = two*2;			
		}
		index = (int) (index + two-1);
		out.print(index+"");
	}
}
class TaskC{
	public void solve(int n, InputReader in, PrintWriter out){
		
	}
}



/**
 * Convenient and fast input reader.
 */
class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;


    public InputReader(InputStream stream){
        reader = new BufferedReader(new InputStreamReader(stream));
    }

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

        return tokenizer.nextToken();
    }
	
	public String nextLine(){
		try{
			return reader.readLine();
		} catch(IOException e){
			throw new RuntimeException("ERROR", e);
		}
	}

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

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