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.
/**
 * Created by IntelliJ IDEA.
 * User: Taras_Brzezinsky
 * Date: 10/27/11
 * Time: 5:55 PM
 * To change this template use File | Settings | File Templates.
 */

import sun.misc.Sort;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;

public class TaskC extends Thread {
    public TaskC(int type) {
        try {
            if (type == 0) {
                this.input = new BufferedReader(new InputStreamReader(System.in));
                this.output = new PrintWriter(System.out);
            } else {
                this.input = new BufferedReader(new FileReader(INPUT_FILE));
                this.output = new PrintWriter(OUTPUT_FILE);
            }
            this.setPriority(Thread.MAX_PRIORITY);
        } catch (Throwable e) {
            e.printStackTrace();
            System.exit(666);
        }
    }

    static boolean isLucky(int value) {
        char []now = Integer.toString(value).toCharArray();
        for (char c : now) {
            if (c != '4' && c != '7') {
                return false;
            }
        }
        return true;
    }

    static void generate(long now, long length) {
        if (length == 10) {
            return;
        }
        luckies.add(now * 10 + 4);
        luckies.add(now * 10 + 7);
        generate(now * 10 + 4, length + 1);
        generate(now * 10 + 7, length + 1);
    }

    //12 ! - max
    private void solve() throws Throwable {
        long facts[] = new long[14];
        facts[0] = 1;
        for (int i = 1; i < facts.length; ++i) {
            facts[i] = facts[i - 1] * i;
        }
        int n = nextInt();
        long k = nextLong();
        if (n <= 12) {
            if (facts[n] < k) {
                output.println(-1);
                return;
            }
        }
        int result = 0;

        int N = 1;
        while (facts[N] < k) {
            ++N;
        }
        long MAX = (long) n - N;
        int index = 0;
        while (index < values.size() && values.get(index) <= MAX) {
            ++result;
            ++index;
        }

        int values[] = new int[N];
        boolean used[] = new boolean[N];
        Arrays.fill(values, -1);
        for (int i = 0; i < N; ++i) {
            for (int wanted = 0; wanted < N; ++wanted) {
                if (used[wanted]) {
                    continue;
                }
                long remaining = facts[N - 1 - i];
                if (remaining < k) {
                    k -= remaining;
                } else {
                    values[i] = wanted + 1;
                    used[wanted] = true;
                    break;
                }
            }
        }
        for (int i = 0; i < N; ++i) {
            int pos = (int)MAX + i + 1;
            if (isLucky(pos) && isLucky((int) MAX + values[i])) {
                ++result;
            }
        }
        output.println(result);

    }

    public void run() {
        try {
            solve();
        } catch (Throwable e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
            System.exit(666);
        } finally {
            output.flush();
            output.close();
        }
    }

    public static void main(String[] args) {
        new TaskC(0).start();
    }

    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    private long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    private double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    private String nextToken() throws IOException {
        while (tokens == null || !tokens.hasMoreTokens()) {
            tokens = new StringTokenizer(input.readLine());
        }
        return tokens.nextToken();
    }

    static ArrayList<Long> values = new ArrayList<Long>();
    static HashSet<Long> luckies = new HashSet<Long>();

    static {
        generate(0, 1);
        values.addAll(luckies);
        Collections.sort(values);
    }

    private static final String INPUT_FILE = null;
    private static final String OUTPUT_FILE = null;
    private BufferedReader input;
    private PrintWriter output;
    private StringTokenizer tokens = null;
}