#include<iostream>
#include<string>
using namespace std;
string S;int p;
int main(){
cin>>S>>p;int b[12];
int n=S.size();int res=0;
for(int i=0;i<(1<<(n-1));i++){
for(int j=0;j<n-1;j++){b[j]=(i/(1<<j))%2;}
string T="";long long cnt=0;
for(int j=0;j<n;j++){
T+=S[j];
if(j<n-1){
if(b[j]>=1){
long long B=stoll(T);
cnt+=B;T="";
}
}
}
if(T!=""){cnt+=stoll(T);}
if(cnt<=p){res++;}
}
cout<<res<<endl;
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPHN0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKc3RyaW5nIFM7aW50IHA7CmludCBtYWluKCl7CgljaW4+PlM+PnA7aW50IGJbMTJdOwoJaW50IG49Uy5zaXplKCk7aW50IHJlcz0wOwoJZm9yKGludCBpPTA7aTwoMTw8KG4tMSkpO2krKyl7CgkJZm9yKGludCBqPTA7ajxuLTE7aisrKXtiW2pdPShpLygxPDxqKSklMjt9CgkJc3RyaW5nIFQ9IiI7bG9uZyBsb25nIGNudD0wOwoJCWZvcihpbnQgaj0wO2o8bjtqKyspewoJCQlUKz1TW2pdOwoJCQlpZihqPG4tMSl7CgkJCQlpZihiW2pdPj0xKXsKCQkJCQlsb25nIGxvbmcgQj1zdG9sbChUKTsKCQkJCQljbnQrPUI7VD0iIjsKCQkJCX0KCQkJfQoJCX0KCQlpZihUIT0iIil7Y250Kz1zdG9sbChUKTt9CgkJaWYoY250PD1wKXtyZXMrKzt9Cgl9Cgljb3V0PDxyZXM8PGVuZGw7CglyZXR1cm4gMDsKfQ==