#include<stdio.h>
#include<math.h>
int main(){
int n,x;
int temp=0,tempB=0,times=1;
register int i=1,j=0;
scanf("%d %d",&n,&x);
if(n<10){
if(x!=0)printf("1");
else printf("0");
}
else {
for(i=10;i<=n;i++){
int tempA[7]={-1,-1,-1,-1,-1,-1,-1};
temp=i;
tempB=0;
for(j=6;j>=0;j--){
if((int)pow(10.0,j)<=temp)tempB=1;
if(tempB){
tempA[j]=temp/(int)pow(10.0,j);
temp%=(int)pow(10.0,j);
}
}
for(j=0;j<7;j++){
if(tempA[j]==x)times++;
}
}
}
if(x!=0)printf("%d",times);
else printf("%d",times-1);
return 0;
}