Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how many lucky numbers in the permutation are located on the positions whose indexes are also lucky numbers.

Input

The first line contains two integers n and k (1 ≤ n, k ≤ 109) — the number of elements in the permutation and the lexicographical number of the permutation.

Output

If the k-th permutation of numbers from 1 to n does not exist, print the single number "-1" (without the quotes). Otherwise, print the answer to the problem: the number of such indexes i, that i and ai are both lucky numbers.

Examples

Input

7 4


Output

1


Input

4 7


Output

1

Note

A permutation is an ordered set of n elements, where each integer from 1 to n occurs exactly once. The element of permutation in position with index i is denoted as ai (1 ≤ i ≤ n). Permutation a is lexicographically smaller that permutation b if there is such a i (1 ≤ i ≤ n), that ai < bi, and for any j (1 ≤ j < i) aj = bj. Let's make a list of all possible permutations of n elements and sort it in the order of lexicographical increasing. Then the lexicographically k-th permutation is the k-th element of this list of permutations.

In the first sample the permutation looks like that:

1 2 3 4 6 7 5

The only suitable position is 4.

In the second sample the permutation looks like that:

2 1 3 4

The only suitable position is 4.
import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;

import static java.lang.Math.*;
 
public class Solution121C {
        
        final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE")!=null;
        BufferedReader in;
        PrintWriter out;
        StringTokenizer tok = new StringTokenizer("");
        
        void init() throws FileNotFoundException{
                if (ONLINE_JUDGE){
                        in = new BufferedReader(new InputStreamReader(System.in));
                        out = new PrintWriter(System.out);
                }else{
                        in = new BufferedReader(new FileReader("input.txt"));
                        out = new PrintWriter("output.txt");
                }
        }
        
        String readString() throws IOException{
                while(!tok.hasMoreTokens()){
                        tok = new StringTokenizer(in.readLine());
                }
                return tok.nextToken();
        }
        
        int readInt() throws IOException{
                return Integer.parseInt(readString());
        }
        
        long readLong() throws IOException{
                return Long.parseLong(readString());
        }
        
        double readDouble() throws IOException{
                return Double.parseDouble(readString());
        }
        
        public static void main(String[] args){
                new Solution121C().run();
        }
        
        public void run(){
                try{
                        long t1 = System.currentTimeMillis();
                        init();
                        solve();
                        out.close();
                        long t2 = System.currentTimeMillis();
                        System.err.println("Time = "+(t2-t1));
                }catch (Exception e){
                        e.printStackTrace(System.err);
                        System.exit(-1);
                }
        }
        ArrayList<Integer> happiens;
        
        int[] cur =  {4,0,0,0,0,0,0,0,0};
        
        boolean Generate(){
        	int c = 0;
        	do{
        		if(cur[c] == 4){
        			cur[c] = 7;
        			String s = "";
        			for(int i = 8; i >= 0; i--){
        				s += Integer.toString(cur[i]);
        			}
        			happiens.add(Integer.parseInt(s));
        			return true;
        		}
        		if(cur[c] == 0){
        			cur[c] = 4;
        			String s = "";
        			for(int i = 8; i >= 0; i--){
        				s += Integer.toString(cur[i]);
        			}
        			happiens.add(Integer.parseInt(s));
        			return true;
        		}
        		
        			cur[c] = 4;
        			c++;
        			if(c >= 9){
        				return false;
        			
        		}
        		
        	}while(true);
        }
        
        ArrayList<Long> perest;
        long[] p;
        
        void Generate(long k, long x, long fact, int i){
        	if(x == 0) return;
        	p[i] = perest.get((int)(k * x / fact));
        	perest.remove(p[i]);
        	long t = k % (fact / x);
        	Generate(t, x-1, fact/x, i+1);
        }
        
        void solve() throws IOException{
        	happiens = new ArrayList<Integer>();
        	happiens.add(4);
        	boolean c = true;
        	do{
        		c = Generate();
        	}while(c);
        	
        	int n = readInt();
        	int k = readInt();
        	int x = 1;
        	long fact = 1;
        	while(fact < k){
        		x++;
        		fact *= x;        		
        	}
        	int count = 0;
        	int curHap = -1;
        	for(int i = 0; i < happiens.size(); i++){
        		if(happiens.get(i) < n-x+1){
        			count++;
        			curHap = i;
        		}
        		else break;
        	}
        	curHap++;
        	if(x > n){
        		out.println(-1);
        		return;
        	}
        	boolean checkHap = false;
        	perest = new ArrayList<Long>();
        	for(long i = n-x+1; i <= n; i++){
        		if(curHap < happiens.size())
        			if(i == happiens.get(curHap)) 
        			checkHap = true;
        		perest.add(i);
        	}
        	if(!checkHap){
        		out.println(count);
        		return;
        	}
        	p = new long[x];
        	Generate(k - 1, x, fact, 0);
        	for(int i = 0; i < p.length; i++){
        		checkHap = false;
        		boolean check2 = false;
        		for(long u: happiens){
        			if(p[i] == u) checkHap = true;
        			if(n-x+1+i == u) check2 = true;
        		}
        		if(checkHap && check2){
        			count++;
        		}
        	}
        	out.println(count);
        }
        
        int ModExp(int a, int n, int mod){
        	int res = 1;
        	while (n!=0)
        		if ((n & 1) != 0) {
        			res = (res*a)%mod;
        			--n;
        		}
        		else {
        			a = (a*a)%mod;
        			n >>= 1;
        		}
        	return res;
        }
        
        
        static class Utils {
 
                private Utils() {}
 
                public static void mergeSort(int[] a) {
                        mergeSort(a, 0, a.length - 1);
                }
 
                private static void mergeSort(int[] a, int leftIndex, int rightIndex) {
                        final int MAGIC_VALUE = 50;
                        if (leftIndex < rightIndex) {
                                if (rightIndex - leftIndex <= MAGIC_VALUE) {
                                        insertionSort(a, leftIndex, rightIndex);
                                } else {
                                        int middleIndex = (leftIndex + rightIndex) / 2;
                                        mergeSort(a, leftIndex, middleIndex);
                                        mergeSort(a, middleIndex + 1, rightIndex);
                                        merge(a, leftIndex, middleIndex, rightIndex);
                                }
                        }
                }
 
                private static void merge(int[] a, int leftIndex, int middleIndex, int rightIndex) {
                        int length1 = middleIndex - leftIndex + 1;
                        int length2 = rightIndex - middleIndex;
                        int[] leftArray = new int[length1];
                        int[] rightArray = new int[length2];
                        System.arraycopy(a, leftIndex, leftArray, 0, length1);
                        System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
                        for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {
                                if (i == length1) {
                                        a[k] = rightArray[j++];
                                } else if (j == length2) {
                                        a[k] = leftArray[i++];
                                } else {
                                        a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];
                                }
                        }
                }
 
                private static void insertionSort(int[] a, int leftIndex, int rightIndex) {
                        for (int i = leftIndex + 1; i <= rightIndex; i++) {
                                int current = a[i];
                                int j = i - 1;
                                while (j >= leftIndex && a[j] > current) {
                                        a[j + 1] = a[j];
                                        j--;
                                }
                                a[j + 1] = current;
                        }
                } 
        }
        
       
        
        boolean isPrime(int a){
        	for(int i = 2; i <= sqrt(a); i++)
        		if(a % i == 0) return false;
        	return true;
        }
        
        static double distance(long x1, long y1, long x2, long y2){
        	return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
        }
        
        static long gcd(long a, long b){
        	if(min(a,b) == 0) return max(a,b);
        	return gcd(max(a, b) % min(a,b), min(a,b));
        }
        
        static long lcm(long a, long b){
        	return a * b /gcd(a, b);
        }
}