#include <iostream>
#include <vector>
#include <string>
#include <cfenv>
#include <cmath>
#include <string>
#include <algorithm>
#include <cstdint>

using namespace std;

long long combination(long long n, int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for (int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}

int len(long long n){//桁数
  for(int i=1; i<101; i++){
    if(n<pow(10,i)) return i;
  }
}

int top(long long n, int i){//先頭の大きさ
  for(int j=2; j<11; j++){
    if(j*pow(10,i)>n) return j-1;
  }
}

long long p(long long n, int k){
  int len = len(n);
  int top = top(n, len);
  return (top-1)*combination(len-1,k)*pow(9,k)+p(n-top*pow(10,len));
}

int main(){
  long long n;
  cin >> n;
  int k;
  cin >> k;

  cout << p << endl;
  return 0;
}
