#pragma warning(disable:4996)

#include <stdio.h>
#include <iostream>
using namespace std;

#define COUNTMAX 100


void numberPlusOne(char *p) {	
	char ch1 = NULL;
	char* ptr = &ch1;
		
	int plus = 1;
	for (int i = COUNTMAX -1; i >= 0; i--) {
		ch1 = p[i];
		int num = atoi(ptr);

		if (num + plus > 9) {
			plus = 1; 			
			p[i] = '0';
		} else {
			plus = 0;						
			itoa(++num, &p[i], 10);
			p[i + 1] = '0';
			break;
		}
	}
}

bool checkNonZero(char* p, int K) {		
	int count = 0;

	for (int i = 0; i <COUNTMAX; i++) {
		char ch = p[i];
		int digits = atoi(&ch);
		if (digits != 0) {						
			count++;
		}
	}
	if (count == K)
		return true;
	else
		return false;	
}

bool checkNumber(char* p1, char* p2) {			
	int count = 0;
	for (int i = 0; i < COUNTMAX; i++) {
		if (p1[i] == p2[i])
			count++;		
	}
	if (COUNTMAX == count)
		return false; // exit
	else
		return true;
}

void copytoLast(char* p)
{
	int len = strlen(p);
	int j = 0;
	for (int i = len; i > 0; i--)
	{
		p[COUNTMAX - i] = p[j];
		p[j] = '\0';
		j++;
	}
}

void main()  {		
	char N[100] = { 0, };
	char N_temp[100] = { 0, };
	int K;
	int intMax = INT_MAX;

	scanf("%s", N);
	scanf("%d", &K);	
	// step : need to check the range of N,K

	copytoLast(N);		

	N_temp[99] = '0';
	int sum = 0;
	bool check = true;
	do {				
		numberPlusOne(N_temp);
		if (checkNonZero(N_temp, K) == true) {
			sum++;
		}
		check = checkNumber(N, N_temp);
	} while (check);

	printf("sum = %d\n", sum);
}