//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor.hpp>
#include <boost/algorithm/string.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;

using ll = long long;
namespace bst = boost;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<string> N;
  in<int> K;
  
  ll dp[10][3][1000];
  
  dp[0][0][0] = 0;
  REP(i, N.length() - 1) {
      if ((i >= N.length() - 2)) {

    REP(j, 9) {
      dp[j+1][0][i] = dp[j][0][i] + 1LL;
    }
    dp[0][0][i+1] = dp[N[N.length() - 1 - i] - '0'][0][i];
      }
    else {
    REP(j, 9) {

      dp[j+1][0][i] = dp[j][0][i] + 1LL;
    }
    dp[0][0][i+1] = dp[9][0][i];

    }
  }
  REP(j, N[0] - '0') {
    dp[j+1][0][N.length() - 1] = dp[j][0][N.length() - 1] + 1LL;
  }
  
  for (int k = 1; k < K; k++) {
    dp[0][k][0] = 0;

    for (int i = k; i < N.length() - 1; i++) {
      if ((i >= N.length() - 2)) {
      REP(j, 9) {
        dp[j+1][k][i] = dp[j][k][i] + dp[0][k - 1][i];
      }
      dp[0][k][i+1] = dp[N[N.length() - 1 - i] - '0'][k][i];
      }
      else {
      REP(j, 9) {
        dp[j+1][k][i] = dp[j][k][i] + dp[9][k - 1][i - 1];
      }
      dp[0][k][i+1] = dp[9][k][i];

      }
    }
    dp[N[0] - '0'][k][N.length() - 1] = dp[N[0] - '0' - 1][k][N.length() - 1] + dp[0][k - 1][N.length() - 1];
 


  }
  
  ll dp2[3][1000];

  dp2[0][0] = 9;
  for (int i = 1; i < N.length() - 1; i++)
    dp2[0][i] = dp2[0][i-1] + 9;
  dp2[0][N.length() - 1] = dp2[0][N.length() - 2] + N[0] - '0' - 1LL;
  
  for (int k = 1; k < K; k++) {
  for (int i = k; i < N.length() - 1; i++)
    dp2[k][i] = dp2[k][i-1] + dp2[k-1][i-1] * 9LL;
  dp2[k][N.length() - 1] = dp2[k][N.length() - 2] + dp2[k-1][N.length() - 2] * (N[0] - '0' - 1);

  }


  return dp2[K-1][N.length() - 1] + dp[N[0] - '0'][K-1][N.length() - 1];
}

template<typename T> void plot(const T& func) { cout << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }
template<> void plot<double()>(double(&func)()) { cout << setprecision(9) << func() << endl; }

int main() {
  plot(solve);

  return 0;
}



