#include <bits/stdc++.h>
using namespace std;
const long long MAX = LLONG_MAX, MOD = 1000000007, MODA = 1e9 - 1;
const long long MIN = LLONG_MIN;
const long double PI = 3.1415926535;
const long long N = 100009;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    string s;
    cin >> s;
    long long k;
    cin >> k;
    long long n = s.length();
    string abc = "";
    for (long long i = 0; i < n; i++) {
      abc += '0';
    }
    long long ans = 0;
    if (k == 1) {
      for (long long i = 0; i < n; i++) {
        if (i == 0)
          ans += s[i] - '0';
        else
          ans += 9;
      }
    }
    if (k == 2) {
      if (n < 2) {
        cout << 0;
        return 0;
      }
      for (long long i = 0; i < n - 1; i++) {
        if (i == 0) {
          ans += (s[i] - '1') * (9 * ((n - 1) - i));
          abc[0] = s[0];
          for (long long j = 1; j < n; j++) {
            for (long long k = 1; k < 10; k++) {
              abc[j] = k + '0';
              if (abc <= s) {
                ans++;
              }
            }
            abc[j] = '0';
          }
        } else {
          ans += (9) * (9 * ((n - 1) - i));
        }
      }
    }
    if (k == 3) {
      if (n < 3) {
        cout << 0;
        return 0;
      }
      for (long long i = 0; i < n - 2; i++) {
        if (i == 0) {
          ans += (s[i] - '1') * (81) * (((n - 1 - i) * (n - 1 - i - 1)) / 2);
          abc[0] = s[0];
          for (long long j = 1; j < n - 1; j++) {
            for (long long k = 1; k < 10; k++) {
              abc[j] = k + '0';
              for (long long l = j + 1; l < n; l++) {
                for (long long m = 1; m < 10; m++) {
                  abc[l] = m + '0';
                  if (abc <= s) ans++;
                }
                abc[l] = '0';
              }
              abc[k] = '0';
            }
          }
        } else {
          ans += (9) * (81) * (((n - 1 - i) * (n - i - 2)) / 2);
        }
      }
    }
    cout << ans;
  }
  return 0;
}
