#include <bits/stdc++.h>
using namespace std;
signed main() {
  string N;
  long long K;
  cin >> N >> K;
  long long M = N.size();
  long long ans = 0;
  if (K == 1) {
    for (long long i = 0; i < M; i++) {
      if (i != M - 1)
        ans += 9;
      else
        ans += N[0] - '0';
    }
    cout << ans << endl;
  } else if (K == 2) {
    for (long long i = 0; i < M - 1; i++)
      for (long long j = i + 1; j < M; j++) {
        if (j != M - 1)
          ans += 81;
        else if (i != M - 2)
          ans += (N[0] - '0') * 9;
        else
          ans += (N[0] - '1') * 9 + (N[1] - '0');
      }
    cout << ans << endl;
  } else {
    for (long long i = 0; i < M - 2; i++)
      for (long long j = i + 1; j < M - 1; j++)
        for (long long k = j + 1; k < M; k++) {
          if (k != M - 1)
            ans += 729;
          else if (j != M - 2)
            ans += (N[0] - '0') * 81;
          else if (i != M - 3) {
            if (N[j] != '0') ans += (N[0] - '1') * 81 + (N[1] - '0') * 9;
          } else {
            if (N[j] != '0' && N[i] != '0')
              ans += (N[0] - '1') * 81 + (N[1] - '1') * 9 + (N[2] - '0');
          }
        }
    cout << ans << endl;
  }
}
