#include <bits/stdc++.h>
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
using namespace std;
void io() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
long long n, ans, k, tmp;
string s;
int main() {
  io();
  cin >> s >> k;
  long long len = s.length();
  long long fir = s[0] - '0';
  if (k == 1)
    cout << 9 * (len - 1) + fir;
  else if (k == 2) {
    for (long long i = len - 1; i >= 2; --i) {
      for (long long j = i - 1; j; --j) {
        ans += 9ll * 9ll;
      }
    }
    for (int i = 1; i < s.length(); ++i) tmp += (s[i] - '0');
    for (int i = 1; i < s.length(); ++i) tmp += 9ll * (fir - 1);
    cout << ans + tmp;
  } else if (k == 3) {
    for (long long i = len - 1; i >= 3; --i) {
      for (long long j = i - 1; j >= 2; --j) {
        for (long long k = j - 1; k; --k) {
          ans += 9ll * 9ll * 9ll;
        }
      }
    }
    for (int i = 1; i < s.length() - 1; ++i) {
      for (int j = i + 1; j < s.length(); ++j) {
        ans += 9ll * 9ll * (fir - 1ll);
        tmp += (s[i] - '0') * (s[j] - '0');
      }
    }
    cout << ans + tmp;
  }
}
