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.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: piyushd
 * Date: 3/26/11
 * Time: 10:53 PM
 * To change this template use File | Settings | File Templates.
 */
public class TaskC {

    long[] fact;

    void precal() {
        this.fact = new long[15];
        fact[0] = 1;
        for(int i = 1; i < 15; i++)
            fact[i] = i * fact[i - 1];
    }

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

    final long LIM = 123456789123L;
    ArrayList<Long> lucky;

    void generate(long x) {
        if(x < LIM) lucky.add(x);
        else return;

        generate(x * 10 + 4);
        generate(x * 10 + 7);
    }

    int totalLucky(int x) {
        if(x < 4) return 0;
        this.lucky = new ArrayList<Long>();
        generate(4);
        generate(7);
        Collections.sort(lucky);

        int low = 0, high = lucky.size();
        while (high - low > 1) {
            int mid = low + (high - low) / 2;
            if(lucky.get(mid) <= x) low = mid;
            else high = mid;
        }

        return low + 1;
    }

    void run() {
        int n = nextInt(), k = nextInt();
        precal();

        int[] a = new int[15];
        Arrays.fill(a, -1);

        boolean[] used = new boolean[15];
        int ix = 0, total = 0;
        while (ix < 15) {
            int cnt = 0, cur = -1;
            for(int i = 0; i < 15; i++)
                if(!used[i]) {
                    if(fact[15 - ix - 1] + total < k) {
                        total += fact[15 - ix - 1];
                        continue;
                    }
                    else {
                        cur = i;
                        break;
                    }
                }

            a[ix] = cur;
            ix++;
            used[cur] = true;
        }

        int ans = 0, correct = 0;
        for(int i = 0; i < 15; i++) {
            if(a[i] == i) correct++;
            else break;
        }

        for(int i = correct; i < 15; i++) {
            int num = a[i] - correct  + 1 + n - (15 - correct);
            int index = i - correct + 1 + n - (15 - correct);
            if(isLucky(num) && isLucky(index)) ans++;
        }

        ans += totalLucky(n - 15 + correct);
        System.out.println(ans);
    }

    int nextInt() {
        try {
            int c = System.in.read();
            if (c == -1) return c;
            while (c != '-' && (c < '0' || '9' < c)) {
                c = System.in.read();
                if (c == -1) return c;
            }
            if (c == '-') return -nextInt();
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = System.in.read();
            } while ('0' <= c && c <= '9');
            return res;
        } catch (Exception e) {
            return -1;
        }
    }

    long nextLong() {
        try {
            int c = System.in.read();
            if (c == -1) return -1;
            while (c != '-' && (c < '0' || '9' < c)) {
                c = System.in.read();
                if (c == -1) return -1;
            }
            if (c == '-') return -nextLong();
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = System.in.read();
            } while ('0' <= c && c <= '9');
            return res;
        } catch (Exception e) {
            return -1;
        }
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String next() {
        try {
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while (Character.isWhitespace(c))
                c = System.in.read();
            do {
                res.append((char) c);
            } while (!Character.isWhitespace(c = System.in.read()));
            return res.toString();
        } catch (Exception e) {
            return null;
        }
    }

    String nextLine() {
        try {
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while (c == '\r' || c == '\n')
                c = System.in.read();
            do {
                res.append((char) c);
                c = System.in.read();
            } while (c != '\r' && c != '\n');
            return res.toString();
        } catch (Exception e) {
            return null;
        }
    }

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