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.*;
import java.io.*;
import java.math.*;
import java.util.*;

import static java.lang.Math.*;

public class BetaRound91_Div1_C implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok;

    public static void main(String[] args) {
        new Thread(null, new BetaRound91_Div1_C(), "", 256 * (1L << 20)).start();
    }

    @Override
    public void run() {
        try {
            long startTime = System.currentTimeMillis();
            if (System.getProperty("ONLINE_JUDGE") != null) {
                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");
            }
            Locale.setDefault(Locale.US);
            tok = new StringTokenizer("");
            solve();
            in.close();
            out.close();
            long endTime = System.currentTimeMillis();
            System.err.println("Time = " + (endTime - startTime));
            long freeMemory = Runtime.getRuntime().freeMemory();
            long totalMemory = Runtime.getRuntime().totalMemory();
            System.err.println("Memory = " + ((totalMemory - freeMemory) >> 10));
        } catch (Throwable t) {
            t.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    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());
    }

    /** http://pastebin.com/j0xdUjDn */
    static class Utils {

        private Utils() {}

        public static void mergeSort(int[] a) {
            mergeSort(a, 0, a.length - 1);
        }

        private static final int MAGIC_VALUE = 50;

        private static void mergeSort(int[] a, int leftIndex, int rightIndex) {
            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;
            }
        }

    }

    // solution

    long[] fact = new long[21];
    
    ArrayList<Long> list = new ArrayList<Long>();
    
    void gen() {
        for (int len = 1; len <= 10; len++) {
            for (int mask = 0; mask < (1 << len); mask++) {
                long res = 0;
                for (int i = 0; i < len; i++) {
                    if (((1 << i) & mask) != 0) {
                        res = 10*res + 7;
                    } else {
                        res = 10*res + 4;
                    }
                }
                list.add(res);
            }
        }
        Collections.sort(list);
        fact[0] = 1;
        for (int i = 1; i <= 20; i++) {
            fact[i] = fact[i - 1] * i;
        }
    }
    
    void solve() throws IOException {       
        gen();
        long n = readLong();
        long k = readLong();
        if (n <= 3) {
            out.println(0);
            return;
        }
        if (k == 1) {
            long ans = Collections.binarySearch(list, n);
            if (ans < 0) {
                ans = -ans - 1;
            } else {
                ans++;
            }
            out.println(ans);
            return;
        }
        int ki = Arrays.binarySearch(fact, k);
        if (ki < 0) {
            ki = -ki - 1;
        }
        long stay = n - ki;
        if (stay < 0) {
            out.println(-1);
            return;
        }
        long ans = Collections.binarySearch(list, stay);
        if (ans < 0) {
            ans = -ans - 1;
        } else {
            ans++;
        }
        p = new long[ki];
        generatePermutation(ki, k);
        for (int i = 0; i < ki; i++) {
            if (isLucky(stay + i + 1) && isLucky(stay + p[i])) {
                ans++;
            }
        }
        out.println(ans);
    }
    
    boolean isLucky(long x) {
        if (x == 0) return false;
        while (x > 0) {
            if (x % 10 != 4 && x % 10 != 7) {
                return false;
            }
            x /= 10;
        }
        return true;
    }
    
    long[] p;
    
    void generatePermutation(int n, long k) {
        boolean[] used = new boolean[n+1];
        k--;
        int nn = n;
        for (int pos = 0; pos < nn; pos++) {
            long d = k / fact[n-1];
            int i = 0;
            int count = 0;
            while (i < nn) {
                i++;
                if (used[i]) continue;
                if (count == d) {
                    used[i] = true;
                    p[pos] = i;
                    break;
                }
                
                count++;
            }
            k -= d * fact[n-1];
            n--;
        }
    }

}