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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AlexFetisov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC_cf91 solver = new TaskC_cf91();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC_cf91 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int res = 0;
            List<Integer> perm = new ArrayList<Integer>();
            int begin = 1, end = n;
            if (n > 13) {
                for (int i = n, j = 0; j < 13; --i, ++j) {
                    perm.add(i);
                }
                Collections.sort(perm);
                res += getLuckyUpTo(n - 13);
                begin = n - 12;
                end = n;
            } else {
                for (int i = 1; i <= n; ++i) {
                    perm.add(i);
                }
            }
            if (k > f(perm.size())) {
                out.println("-1");
                return;
            }
            perm = getK(k, perm);
            for (int i = begin; i <= end; ++i) {
                if (isLucky(perm.get(i - begin)) && isLucky(i)) {
                    ++res;
                }
            }
            out.println(res);
        }

        private List<Integer> getK(int k, List<Integer> ip) {
            List<Integer> p = new ArrayList<Integer>();
            int n = ip.size();
            boolean[] have = new boolean[n];
            for (int i = 0; i < n; ++i) {
                for (int d = 0; d < n; ++d) {
                    if (!have[d]) {
                        long rest = f(n - i - 1);
                        if (rest >= k) {
                            p.add(d);
                            have[d] = true;
                            break;
                        } else {
                            k -= rest;
                        }
                    }
                }
            }
            int[] shuffled = new int[n];
            for (int i = 0; i < n; ++i) {
                shuffled[i] = ip.get(p.get(i));
            }
            for (int i = 0; i < n; ++i) {
                p.set(i, shuffled[i]);
            }
            return p;
        }

        private int getLuckyUpTo(int upTo) {
            int res = 0;
            for (int len = 1; len <= 10; ++len) {
                for (int mask = 0; mask < (1 << len); ++mask) {
                    long number = 0;
                    for (int i = 0; i < len; ++i) {
                        if (BitUtils.checkBit(mask, i)) {
                            number = number * 10L + 7;
                        } else {
                            number = number * 10L + 4;
                        }
                    }
                    if (number <= upTo) {
                        ++res;
                    }
                }
            }
            return res;
        }

        boolean isLucky(int x) {
            if (x == 0) return false;
            while (x != 0) {
                int c = x % 10;
                x /= 10;
                if (c != 4 && c != 7) return false;
            }
            return true;
        }

        long f(int upTo) {
            long res = 1L;
            for (long i = 2; i <= upTo; ++i) {
                res *= i;
            }
            return res;
        }

    }

    static class BitUtils {
        public static boolean checkBit(int mask, int bit) {
            return (mask & (1 << bit)) > 0;
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer stt;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public String nextString() {
            while (stt == null || !stt.hasMoreTokens()) {
                stt = new StringTokenizer(nextLine());
            }
            return stt.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}

