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 javax.sound.sampled.Line;
import java.awt.Point;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import static java.math.BigInteger.*;

import java.math.MathContext;
import java.util.*;
public class C{


    void testIt()
    {
        Random rand=new Random();
        for(int test=1;;test++)
        {

            int n=Math.abs(rand.nextInt()%1000000000)+1;
            long k=Math.abs(rand.nextInt()%1000000000)+1;
            System.out.println(test+" "+n+" "+k);
            long cur=doIt( n,k);

            System.out.println(cur);
        }
    }

    private long doIt(int n, long k) {
               all=new ArrayList<Long>();
              get(0,(long)7777777777L);
              Collections.sort(all);
              ArrayList<Integer>a=new ArrayList<Integer>();
              long z=1;
              for(int i=1;i<=n;i++)
              {
                  z*=i;
                  if(z>=k)
                      break;
              }
              if(z<k)
              {
                  return -1;
              }
              while (a.size()<15 && n>0)
              {
                  a.add(n);
                  n--;
              }
              Collections.reverse(a);
              int res=0;
              for(Long x: all)
                  if(x<=n)
                      res++;
              long[]fact=new long[a.size()];
              for(int i=0;i<fact.length;i++)
                  if(i==0)
                      fact[i]=1;
                  else
                      fact[i]=i*fact[i-1];
              boolean []used=new boolean[a.size()];
              int[]x=new int[used.length];
              for(int at=0;at<a.size();at++)
              {

                  long who=0;
                  while (k>fact[a.size()-1-at])
                  {
                      k-=fact[a.size()-1-at];
                      who++;
                  }

                  int ans=-1;
                  for(int i=0;i<a.size();i++)
                      if(!used[i])
                      {
                          who--;
                          if(who==-1)
                          {
                              ans=i;
                              break;
                          }
                      }
                  used[ans]=true;
                  x[at]=a.get(ans);
                  //System.out.println(x[at]);
              }
              for(int i=0;i<a.size();i++)
              {
                  if(all.indexOf((long)x[i])>=0 && all.indexOf((long)(i+1+n))>=0)
                      res++;
              }
              return res;

    }

    ArrayList<Long>all;
    void solve()throws Exception
    {



        int n=nextInt();
        long k=nextInt();
        System.out.println(doIt(n,k));



    }
    void get(long cur,long max)
    {
        if(cur>max)
            return;
        if(cur!=0)
            all.add(cur);
        get(10*cur+4,max);
        get(10*cur+7,max);

    }

    ////////////
    BufferedReader reader;
    PrintWriter writer;
    StringTokenizer stk;
    void run()throws Exception
    {
        reader=new BufferedReader(new InputStreamReader(System.in));
        stk=null;
        writer=new PrintWriter(new PrintWriter(System.out));
        solve();
        reader.close();
        writer.close();
    }
    int nextInt()throws Exception
    {
        return Integer.parseInt(nextToken());
    }

    long nextLong()throws Exception
    {
        return Long.parseLong(nextToken());

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


    }

    String nextString()throws Exception
    {
        return nextToken();
    }
    String nextLine()throws Exception
    {
        return reader.readLine();
    }
    String nextToken()throws Exception
    {
        if(stk==null || !stk.hasMoreTokens())
        {
            stk=new StringTokenizer(nextLine());
            return nextToken();

        }
        return stk.nextToken();
    }

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



}