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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;

public class Solution{
	
	
	
	
    public static void main(String[] args) throws IOException {
     
    	FastScanner fs = new FastScanner();
    	PrintWriter out = new PrintWriter(System.out);
    	
    	
    		
    	int tt = 1;
    	while(tt-->0) {
    		
    		long n = fs.nextLong(), k = fs.nextLong();
    		
    		long ans = 0;
    		long first = Math.max(1, n-12);
    		
    		ans += getLucky(first-1);
    		
    		long[] fact = new long[15];
    		fact[0] = 1;
    		for(int i=1;i<15;i++) fact[i] = fact[i-1]*i;
    		
    		HashSet<Long> set = new HashSet<>();
    		
    		
    		long pos = first;
    		
    		if(k>fact[(int)(n-pos+1)]) {
    			out.println(-1);
    			out.flush();
    			return;
    		}
    		
    		for(long p=pos; p<=n;p++) {
    			
    			for(long i=first;i<=n;i++) {
    				if(!set.contains(i)) {
    					long f = fact[(int)(n-p)];
    					if(f<k) {
    						k -= f;
    					}
    					else {
    						set.add(i);
    						ans += (isLucky(i)&&isLucky(p))?1:0;
    						if(p==n) k--;
    						break;
    					}
    					int l = 1;
    				}
    			}
    			
    		}
    		
    		
    		if(k>0) {
    			out.println(-1);
    		}
    		else {
    			out.println(ans);
    		}
    		
    		
    		
    	}
    	
    		
    		
    		
    	out.close();
    		
    }
    
    
    static boolean isLucky(long n) {
    	while(n>0) {
    		int d = (int)n%10;
    		if(!(d==4 || d==7)) return false;
    		n /= 10;
    	}
    	return true;
    }
    
    
    static long getLucky(long num) {
    	if(num==0) return 0;
    	int d = getDigit(num);
    	long cnt = (1L<<d)-2;
    	long p = 1;
    	for(int i=0;i<d-1;i++) p *= 10;
    	long k = 0;
    	for(int i=d-1;i>=0;i--) {
    		int dig = ((int)(num/(p)))%10;
    		if(i==0) {
    			if(dig>=7) k+= 2;
    			else if(dig>=4) k+= 1;
    			break;
    		}
    		if(dig>7) {
    			k += (1L<<(i+1)); break;
    		}
    		else if(dig==7) {
    			k += (1L<<i);
    		}
    		else if(dig>4) {
    			k += (1L<<i); break;
    		}
    		else if(dig<4) {
    			break;
    		}
    		p /= 10;
    	}
    	cnt += k;
    	return cnt;
    }
    
    
    static int getDigit(long n) {
    	int cnt = 0;
    	while(n>0) {
    		cnt++;
    		n /= 10;
    	}
    	return cnt;
    }
    
    
  
    
    
    static final Random random=new Random();
    	
    static void ruffleSort(int[] a) {
    	int n=a.length;//shuffle, then sort 
    	for (int i=0; i<n; i++) {
    		int oi=random.nextInt(n); int temp=a[oi];
    		a[oi]=a[i]; a[i]=temp;
    	}
    	Arrays.sort(a);
    }
    
    static void ruffleSort(long[] a) {
    	int n=a.length;//shuffle, then sort 
    	for (int i=0; i<n; i++) {
    		int oi=random.nextInt(n); long temp=a[oi];
    		a[oi]=a[i]; a[i]=temp;
    	}
    	Arrays.sort(a);
    }
   
  
    
    static void reverse(int[] arr, int l, int r) {
    	for(int i=l;i<l+(r-l)/2;i++){
    		int temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;
    	}
    }
    
    static void reverse(long[] arr, int l, int r) {
    	for(int i=l;i<l+(r-l)/2;i++){
    		long temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;
    	}
    }
    
    
    static <T> void reverse(T[] arr, int l, int r) {
    	for(int i=l;i<l+(r-l)/2;i++) {
    		T temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;
    	}
    }
    	
    	
    static class FastScanner{
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st = new StringTokenizer("");
     
    	public String next(){
    		while(!st.hasMoreElements()){
    			try{
    				st = new StringTokenizer(br.readLine());
    			} catch(IOException e){
    				e.printStackTrace();
    			}
    		}
    		return st.nextToken();
    	}
    		
    	public String nextLine() throws IOException {
    		return br.readLine();
    	}
    		
    	public int nextInt(){
    		return Integer.parseInt(next());
    	}
     
    	public int[] readArray(int n){
    		int[] a = new int[n];
    		for(int i=0;i<n;i++)
    			a[i] = nextInt();
    		return a;
    	}
    		
    	public long nextLong() {
    		return Long.parseLong(next());
    	}
    		
    	public char nextChar() {
    		return next().toCharArray()[0];
    	}
    }
   	
}
