#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
const int mod=1e9+7;
char s[maxn];int n,vis[300],ans=0,cnt=0;
int dp[maxn][17],f[maxn][17][17];
int mp[300];
void dfs(int pos)
{
	if(pos>n)	return;
	
	for(int i=1;i<=16;i++){
		dp[pos][i]=(dp[pos][i]+1LL*i*dp[pos-1][i]%mod)%mod;
		dp[pos][i]=(dp[pos][i]+1LL*(17-i)*dp[pos-1][i-1]%mod)%mod;
	}
	if(pos!=1){
		dp[pos][1]=(dp[pos][1]+15)%mod;
	}else{
		dp[pos][1]=(dp[pos][1]+(mp[s[pos]]-1))%mod;
	}
	
	if(pos!=1){
		for(int i=0;i<mp[s[pos]];i++){
			if(vis[i]==0)
				dp[pos][cnt+1]=(dp[pos][cnt+1]+1)%mod;
			else
				dp[pos][cnt]=(dp[pos][cnt]+1)%mod;
		}
	}
	
	
	if(vis[mp[s[pos]]]==0)	cnt++,vis[mp[s[pos]]]=1;
	//cout<<pos<<" "<<dp[pos][1]<<endl;
	dfs(pos+1);
}
int main()
{
	for(int i=0;i<10;i++)	mp[i+'0']=i;
	for(int i=0;i<6;i++)	mp[i+'A']=i+10;
	scanf("%s",s+1);n=strlen(s+1);int k;scanf("%d",&k);
	dfs(1);if(cnt==k)	dp[n][k]++;
	cout<<dp[n][k]<<endl;
}
#include<iostream>
#include<cstdlib>
#include<utility>
#include<tuple>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<queue>
#include<deque>
#include<bitset>
#include<cmath>
#include<map>
#include<string>
#include<iomanip>
#include<set>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const double PI = acos(-1);
#define rep(i, a, b) for(ll i = a; i < b; i++)

ll repeat(ll x) {
	ll res = 1;
	rep(i, 0, x)res *= 10;
	return res;
}

int main() {

	string s;
	cin >> s;
	ll n = s.size();
	bool ans = false;
	if (n == 1) {
		if (stoi(s) == 8) ans = true;
	}else if (n == 2) {
		if (stoi(s) % 8 == 0) ans = true;
		swap(s[0], s[1]);
		if (stoi(s) % 8 == 0) ans = true;
	}
	else {
		vector<ll> x(11, 0);
		rep(i, 0, n) {
			x[s[i] - '0']++;
		}

		if (x[0] >= 2 && x[8] >= 1) ans = true;
		else if (x[0] >= 1) {
			for (ll i = 16; i < 100; i += 8) {
				s = to_string(i);
				if (x[s[0]] >= 1 && x[s[1]] >= 1) ans = true;
			}
		}
		else {
			for (ll i = 104; i < 1000; i += 8) {
				s = to_string(i);
				x[s[0] - '0']--; x[s[1] - '0']--; x[s[2] - '0']--;
				if (x[s[0] - '0'] >= 0 && x[s[1] - '0'] >= 0 && x[s[2] - '0'] >= 0)
					ans = true;
				x[s[0] - '0']++; x[s[1] - '0']++; x[s[2] - '0']++;
			}
		}
	}

	if (ans)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}