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.
#include<stdio.h>
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<sstream>
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>

using namespace std;


// Input macros
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%lld",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)

#define ll long long

// Useful constants
#define INF                         (int)1e9
#define EPS                         1e-7

// Useful hardware instructions
#define bitcount                    __builtin_popcount
#define gcd                         __gcd

// Useful container manipulation / traversal macros
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair

//#define tr(container, it)    for(auto it = container.begin(); it != container.end(); it++)
#define tr(container, it)    for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

// Some common useful functions
#define maX(a,b)                     ( (a) > (b) ? (a) : (b))
#define miN(a,b)                     ( (a) < (b) ? (a) : (b))
#define checkbit(n,b)                ( (n >> b) & 1)
#define DREP(a)                      sort(all(a)); a.erase(unique(all(a)),a.end())
#define INDEX(arr,ind)               (lower_bound(all(arr),ind)-arr.begin())

#define mod 1000000007

#define ld long double
#define llu unsigned ll

//int scan_d()    {int ip=getchar_unlocked(),ret=0,flag=1;for(;ip<'0'||ip>'9';ip=getchar_unlocked())if(ip=='-'){flag=-1;ip=getchar_unlocked();break;}for(;ip>='0'&&ip<='9';ip=getchar_unlocked())ret=ret*10+ip-'0';return flag*ret;}
//ld scan_ld()    {int ip=getchar_unlocked(),flag=1;ld ret=0;for(;ip<'0'||ip>'9';ip=getchar_unlocked())if(ip=='-'){flag=-1;ip=getchar_unlocked();break;}for(;ip>='0'&&ip<='9';ip=getchar_unlocked())ret=ret*10+ip-'0';return flag*ret;}
//ll scan_ll()    {int ip=getchar_unlocked(),flag=1;ll ret=0;for(;ip<'0'||ip>'9';ip=getchar_unlocked())if(ip=='-'){flag=-1;ip=getchar_unlocked();break;}for(;ip>='0'&&ip<='9';ip=getchar_unlocked())ret=ret*10+ip-'0';return flag*ret;}
//llu scan_llu()    {int ip=getchar_unlocked();llu ret=0;for(;ip<'0'||ip>'9';ip=getchar_unlocked());for(;ip>='0'&&ip<='9';ip=getchar_unlocked())ret=ret*10+ip-'0';return ret;}

//end of fast input

int array[13];
int n;



template<typename set> typename set::iterator
greatest_less(set & m, typename set::key_type const& k) {
    typename set::iterator it = m.lower_bound(k);
    if(it != m.begin()) {
        return --it;
    }
    return m.end();
}

ll factorial[15];
vector<ll> luckyones;

ll convert(int a)
{
    ll tmp=0,tenpower=1;
    int val;
    while(a > 0)
    {
        if(a%2 == 1)
            val = 7;
        else
            val = 4;
        a = a>>1;
        tmp = tmp + (val)*tenpower;
        tenpower = tenpower*10;
    }
    return tmp;
}

void generateluckynum()
{
    for(int i=1;i<1000;i++)
    {
        luckyones.push_back(convert(i));
    }
}

void facto()
{
    factorial[0] = 1;
    for(int i =1;i<15;i++)
    {
        factorial[i] = factorial[i-1]*i;
    }
}

bool compare(int a,int b)
{
    return a>b;
}

bool islucky(int a)
{
    int tmp;
    while(a>0)
    {
        tmp = a%10;
        if(tmp != 4 && tmp != 7)
            return false;
        a = a/10;
    }
    return true;
}

int kthpermutation(int* a,int n,int k)
{

    sort(a,a+n);

    int count=0,tmpk,itr,flag;

    for(int i=0;i<n;i++)
    {
        tmpk = k;
        itr = i+1;
        flag=0;
        while(tmpk > 0)
        {
            tmpk = tmpk-factorial[n-i-1];

            if(tmpk > 0)
            {
                swap(a[i],a[itr]);
                k = tmpk;
                itr++;
            }
            else if(tmpk == 0)
            {
                sort(a+i+1,a+n,compare);
                flag = 1;
                break;
            }
            else
            {
                break;
            }

        }
        if(flag == 1)
            break;
    }


    int ind=0;
    for(int i=n-1;i>=0;i--)
    {
        //cout<<(::n - ind)<<" : "<<a[i]<<" : ";
        if(islucky(::n - ind) && islucky(a[i]))
            count++;
        ind++;
        //cout<<count<<endl;
    }
    return count;
}

int main() {

    int k,nn;
    facto();
    //cout<<"facto done!\n";
    generateluckynum();
    //cout<<"felt lucky\n";
    cin>>n;
    cin>>k;
    int val = n-13;
    if(val < 0)
        nn = n;
    else
        nn = 13;
    int count = 0;
    if(val > 0)
    count = (upper_bound(luckyones.begin(),luckyones.end(),val) - luckyones.begin());
    for(int i=0;i<nn;i++)
    {
        array[i] = n-i;
    }
    count += kthpermutation(array,nn,k);
    cout<<count<<endl;
   return 0;
}
