#include<bits/stdc++.h>
using namespace std;
/*/---------------------------Defines-----------------------------------------/*/
#pragma GCC optimize("Ofast")
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n; i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
#define PI 3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;
const int INF = 1e18L;
// for all eight directions
int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
// for all 4 directions
//int dx[4]={-1,1,0,0};
//int dy[4]={0,0,-1,1};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/*/-----------------------------Debug begins----------------------------------/*/
vector<string> split(const string& s, char c) {
vector<string> v; stringstream ss(s); string x;
while (getline(ss, x, c)) v.emplace_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
stringstream s; s << "[";
for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
if(n>0)
s << arr[n - 1] ;
s<< "]";
return s.str();
}
#define trace(args...) {__trace_begin(__LINE__); __trace(split(#args, ',').begin(), args);}
inline void __trace_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __trace_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __trace_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __trace_out_var(T val) { cerr << val; }
inline void __trace(vector<string>::iterator it) { cerr << endl; }
template<typename T, typename... Args>
inline void __trace(vector<string>::iterator it, T a, Args... args) {
cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
__trace_out_var(a);
cerr << "; ";
__trace(++it, args...);
}
/*/-----------------------------Code begins----------------------------------/*/
int ar[N];
map<pair<pair<int,int>,pair<bool,bool> >,int>dp;
int n,k;
vector<int>v;
string no;
int solve(int pos,int p,bool f,bool st){
if(pos == n){
return p<=k;
}
if(dp.find({{pos,p},{f,st}})!=dp.end())return dp[{{pos,p},{f,st}}];
int ans =0 ;
int lim = (f ==0 ? v[pos] : 9);
for(int i=0;i<=lim;i++){
bool nf =f ;
int np = p;
np*=i;
if(f ==0 && i < lim)nf =1;
if(i ==0 && st ==0 ){
ans+=solve(pos+1,p,nf,0);
}else{
ans+=solve(pos+1,np,nf,1);
}
}
return dp[{{pos,p},{f,st}}] =ans;
}
signed main(){
IOS;
int T=1;
// cin >> T;
while(T--){
cin >> n >> k ;
while(n){
v.pb(n%10);
n/=10;
}
reverse(all(v));
n = v.size();
int ans = solve(0,1,0,0);
--ans;
cout << ans;
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsgICAgCgovKi8tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS1EZWZpbmVzLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0vKi8KCiNwcmFnbWEgR0NDIG9wdGltaXplKCJPZmFzdCIpIAojZGVmaW5lIGludCBsb25nIGxvbmcKI2RlZmluZSBJT1MgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7Y2luLnRpZShOVUxMKTsKI2RlZmluZSBwYiBwdXNoX2JhY2sgCiNkZWZpbmUgZWIgZW1wbGFjZV9iYWNrCiNkZWZpbmUgZm4gZm9yKGludCBpID0wIDtpIDxuO2krKykgIAojZGVmaW5lIGZuMSBmb3IoIGludCBpID0xO2k8PW47IGkrKykKI2RlZmluZSBmbSBmb3IoaW50IGogPTAgO2ogPG07aisrKQojZGVmaW5lIGZtMSBmb3IoaW50IGogPTE7ajw9bTtqKyspCiNkZWZpbmUgZmkgZmlyc3QKI2RlZmluZSBzZSBzZWNvbmQKI2RlZmluZSBlbmRsICdcbic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