#include <bits/stdc++.h>
using namespace std;
long long get() {
  char c = getchar();
  long long x = 0LL;
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') {
    x *= 10LL;
    x += (c - '0');
    c = getchar();
  }
  return x;
}
string s;
int krk;
long long ans;
int main() {
  ios::sync_with_stdio(0);
  cin >> s >> krk;
  if (s.size() < krk) {
    cout << 0;
    ;
    return 0;
  }
  if (krk == 1) {
    for (int i = 1; i <= 9; i++) {
      ans += s.size() - 1;
      if (i <= s[0] - '0') ans++;
    }
  } else {
    if (krk == 2) {
      for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
          ans += (s.size() - 1) * (s.size() - 2) / 2;
          if (i > s[0] - '0') continue;
          if (i < s[0] - '0')
            ans += s.size() - 1;
          else {
            bool f = false;
            for (int k = 1; k < s.size(); k++) {
              if (f) {
                ans++;
                continue;
              }
              if (s[k] - '0' >= j) {
                f = true;
                ans++;
              }
              if (s[k] - '0' > 0) f = true;
            }
          }
        }
      }
    } else {
      for (int i = 1; i < 10; i++)
        for (int j = 1; j < 10; j++)
          for (int k = 1; k < 10; k++) {
            ans += (s.size() - 1) * (s.size() - 2) * (s.size() - 3) / 6;
            if (i > s[0] - '0') continue;
            if (i < s[0] - '0')
              ans += (s.size() - 1) * (s.size() - 2) / 2;
            else {
              bool f = false;
              for (int j1 = 1; j1 < s.size() - 1; j1++) {
                for (int k1 = j1 + 1; k1 < s.size(); k1++) {
                  if (f) {
                    ans++;
                    continue;
                  }
                  if (s[j1] - '0' < j) continue;
                  if (s[j1] - '0' > j) {
                    ans++;
                    f = true;
                  } else {
                    if (s[k1] - '0' < k) continue;
                    if (s[k1] - '0' >= k) {
                      ans++;
                      f = true;
                    }
                    if (s[k1] - '0' > 0) f = true;
                  }
                }
                if (s[j1] - '0' > 0) f = true;
              }
            }
          }
    }
  }
  cout << ans;
  return 0;
}
