#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int dp[s.size()][k + 1][2];
  for (int i = 0; i < (int)(s.size() + 1); i++)
    for (int j = 0; j < (int)(k + 1); j++)
      for (int h = 0; h < (int)(2); h++) dp[i][j][h] = 0;
  dp[0][0][0] = 1;
  for (int i = 0; i < s.size(); i++) {
    int x = s[i] - '0';
    int ni = i + 1;
    for (int j = 0; j < (int)(k + 1); j++) {
      for (int a = 0; a < (int)(10); a++) {
        int nj = j;
        if (a != 0) nj = j + 1;
        if (nj > k) continue;
        for (int h = 0; h < (int)(2); h++) {
          int nk = 0;
          if ((x == a && h == 1) || (x == a && i == 0))
            nk = 1;
          else if ((h == 1 && a > x) || (i == 0 && a > x))
            break;
          dp[ni][nj][nk] += dp[i][j][h];
        }
      }
    }
  }
  cout << dp[s.size()][k][0] + dp[s.size()][k][1] << endl;
  return 0;
}
