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.awt.Point;
import java.awt.font.GraphicAttribute;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.MathContext;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.logging.Level;
 








import javax.swing.text.MutableAttributeSet;
 
 
 
public  class TestClass {
 static int k;
static int[] cost;
static HashMap<String,Integer> vis;
public static void check(int n ,long x){
	if(k==1) return;
	 
	if(x%n==0){
		 System.out.println(x);
		 k=1;
	 }
	check(n, 10*x);
	check(n, (10*x+9));
	
}
public static int search(int curr ,ArrayList<Integer>[] maps , int prev){
	int ans=1;
	
	ArrayList<Integer> mm = new ArrayList<Integer>();
	for(int i=0;i<maps[curr].size();i++){
		 int xx = maps[curr].get(i);
		 if(xx!=prev)
			{
			 cost[xx]=search(xx, maps,curr);
			 mm.add(cost[xx]);
			}
	
	}
	Collections.sort(mm);
 if(mm.size()!=0){
	 if(mm.size()==1) return 1;
	 
	 cost[curr] = 1+ mm.get(mm.size()-1)+mm.get(mm.size()-2);
	 return cost[curr];
 }

	 
	
	 
	return ans;
}
public static boolean check(String A , String B , int k){
	

	 int ans=0;
	  int min = Math.min(A.length(),B.length());
	  int max = Math.max(A.length(),B.length());
	  ans+=max-min;
	  
	  for(int i=0;i<min;i++){
		  
		   if(ans>k) return false;
		   if(A.charAt(i)!=B.charAt(i)) ans++;
	  }
	  if(ans>k) return false;
	  
	//  System.out.println(A+" "+B);
	  
	  return true;
}
public static void main(String args[] ) throws IOException  {
 
 
 
///InputStream inputStream = System.in;
 //InputReader in = new InputReader(inputStream);
 
    // BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
 // BufferedReader in = new BufferedReader(new FileReader("C:\\Users\\Sompathak\\Desktop\\yes.txt"));
   //Scanner in = new Scanner(new FileReader("C:\\Users\\Sompathak\\Desktop\\yes.txt"));
   // PrintWriter pw = new PrintWriter(new FileWriter("C:\\Users\\Sompathak\\Desktop\\output.txt"));
   	//InputStream inputStream = System.in;
   	//InputReader in = new InputReader(inputStream);
   Scanner in = new Scanner(new InputStreamReader(System.in));
//Scanner in = new Scanner(new FileReader("C:\\Users\\Sompathak\\Desktop\\yes.txt"));
	//we can we will ??? !!!!!! SOM     RISES
ArrayList<Integer> m = new ArrayList<Integer>();
int n = in.nextInt();
long pow=1;
int ans=1;
if(n%10==7) ans=2;
n/=10;
while(n!=0){
	int xx = n%10;
	n/=10;
	pow*=2;
	if(xx==7) ans+=2*pow;
	else ans+=pow;
}
System.out.println(ans);
	

}
public static class InputReader
{
    private InputStream stream; 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 readDouble() {
        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 readLong() {
        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 interface SpaceCharFilter
    {
        public boolean isSpaceChar(int ch);
    }
}
 }     