#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const long long MOD = 998244353;
string s;
vector<int> N;
int dp[100][2][4];
int main(void) {
  cin >> s;
  int k;
  cin >> k;
  int l = s.size();
  for (int i = 0; i < (int)(l); i++) N.push_back(s[i] - '0');
  dp[0][0][0] = 1;
  dp[0][0][1] = 0;
  dp[0][0][2] = 0;
  dp[0][0][3] = 0;
  dp[0][1][0] = 0;
  dp[0][1][1] = 0;
  dp[0][1][2] = 0;
  dp[0][1][3] = 0;
  for (int i = 0; i < (int)(l); i++) {
    for (int smaller = 0; smaller < (int)(2); smaller++) {
      for (int j = 0; j < (int)(4); j++) {
        for (int x = 0; x <= (smaller ? 9 : N[i]); x++) {
          if (x == 0) {
            dp[i + 1][smaller || x < N[i]][j] += dp[i][smaller][j];
          } else {
            if (j != k) {
              dp[i + 1][smaller || x < N[i]][j + 1] += dp[i][smaller][j];
            }
          }
        }
      }
    }
  }
  cout << dp[l][0][k] + dp[l][1][k] << endl;
  return 0;
}
