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
/**
 * Prerequisite:
 * Algorithm:
 */

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.Queue;

public class _535B_TavasAndSaDDas{
	static class ProblemSolver{
		public void solveTheProblem(InputReader in,PrintWriter out){
			int n=in.nextInt();
			ArrayList<Integer> luckyNumbers=new ArrayList<>();
			luckyNumbers.add(4);
			luckyNumbers.add(7);
			Queue<Integer> queue=new ArrayDeque<>();
			queue.add(0);
			int counter=0;
			while(true){
				int number=queue.poll();
				int firstNumber=number*10+4;
				int secondNumber=number*10+7;
				queue.add(firstNumber);
				++counter;
				if(firstNumber==n){
					out.print(counter);
					return;
				}
				queue.add(secondNumber);
				++counter;
				if(secondNumber==n){
					out.print(counter);
					return;
				}
			}
		}
	}

	//User defined InputReader class for all the codes for fast IO
	//Refer the class ProblemSolver explicitly for main code
	static class InputReader{
		private InputStream stream;
		private byte[] buf=new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream){
			this.stream=stream;
		}

		public int read(){
			if(numChars==-1) throw new InputMismatchException();
			if(curChar>=numChars){
				curChar=0;
				try{
					numChars=stream.read(buf);
				}catch(IOException e){
					throw new InputMismatchException();
				}
				if(numChars<=0) return -1;
			}
			return buf[curChar++];
		}

		public int nextInt(){
			int c=read();
			while(isSpaceChar(c)) c=read();
			int sgn=1;
			if(c=='-'){
				sgn=-1;
				c=read();
			}
			int res=0;
			do{
				if(c<'0' || c>'9')
					throw new InputMismatchException();
				res*=10;
				res+=c-'0';
				c=read();
			}while(!isSpaceChar(c));
			return res*sgn;
		}

		public String readString(){
			int c=read();
			while(isSpaceChar(c)) c=read();
			StringBuilder res=new StringBuilder();
			do{
				res.appendCodePoint(c);
				c=read();
			}while(!isSpaceChar(c));
			return res.toString();
		}

		public double nextDouble(){
			int c=read();
			while(isSpaceChar(c))
				c=read();
			int sgn=1;
			if(c=='-'){
				sgn=-1;
				c=read();
			}
			double res=0;
			while(!isSpaceChar(c) && c!='.'){
				if(c=='e' || c=='E')
					return res*Math.pow(10,nextInt());
				if(c<'0' || c>'9')
					throw new InputMismatchException();
				res*=10;
				res+=c-'0';
				c=read();
			}
			if(c=='.'){
				c=read();
				double m=1;
				while(!isSpaceChar(c)){
					if(c=='e' || c=='E')
						return res*Math.pow(10,nextInt());
					if(c<'0' || c>'9')
						throw new InputMismatchException();
					m/=10;
					res+=(c-'0')*m;
					c=read();
				}
			}
			return res*sgn;
		}

		public long nextLong(){
			int c=read();
			while(isSpaceChar(c))
				c=read();
			int sgn=1;
			if(c=='-'){
				sgn=-1;
				c=read();
			}
			long res=0;
			do{
				if(c<'0' || c>'9')
					throw new InputMismatchException();
				res*=10;
				res+=c-'0';
				c=read();
			}while(!isSpaceChar(c));
			return res*sgn;
		}

		public boolean isSpaceChar(int c){
			if(filter!=null)
				return filter.isSpaceChar(c);
			return c==' ' || c=='\n' || c=='\r' || c=='\t' || c==-1;
		}

		public String next(){
			return readString();
		}

		public int[] nextIntArray(int size){
			int[] array=new int[size];
			for(int i=0;i<size;i++)
				array[i]=nextInt();
			return array;
		}

		public interface SpaceCharFilter{
			boolean isSpaceChar(int ch);
		}
	}

	//Main method for all the codes
	public static void main(String... strings){
		InputStream inputStream=System.in;
		OutputStream outputStream=System.out;
		InputReader in=new InputReader(inputStream);
		PrintWriter out=new PrintWriter(outputStream);
		ProblemSolver problemSolver=new ProblemSolver();
		problemSolver.solveTheProblem(in,out);
		out.close();
	}

}