#include <stdio.h>
#include <stdlib.h>
int main()
{
int n, x, i, j, m, N, s[10], a, b, c, d, e, f, h;
scanf("%d %d", &n, &x);
m = 0;
for (i=1; i<=n; i++) //n次循环,遍历n个数
{
a = i/1000000; //分解1000000内数字的各个位数字
b = (i%1000000) / 100000;
c = (i%100000) / 10000;
d = (i%10000) / 1000;
e = (i%1000) / 100;
f = (i%100) / 10;
h = i%10;
s[0] = h; //将各个位上的数字赋值到数组s中
s[1] = f;
s[2] = e;
s[3] = d;
s[4] = c;
s[5] = b;
s[6] = a;
if(i < 10) N = 1; //判断数字位数,将位数赋值给N作为循环搜索条件
if(9<i && i<100) N = 2;
if(99<i && i<1000) N = 3;
if(999<i && i<10000) N = 4;
if(9999<i && i<100000) N = 5;
if(99999<i && i<1000000) N = 6;
if(999999<i && i<10000000) N = 7;
for (j=0; j<N; j++) //对N位数的N次循环搜索
{
if (s[j] == x)
{
m++;
}
}
}
printf("%d\n", m);
return 0;
}