#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 228;
const long long MAXN = 1e5 + 228;
string n;
long long k;
void solve1() {
  long long ans = 0;
  for (long long i = 0; i < n.size(); i++) {
    if (i != 0) {
      ans += 9;
      continue;
    }
    long long f = n[0] - '0';
    ans += f;
  }
  cout << ans << endl;
}
void solve2() {
  long long ans = 0;
  for (long long i = 0; i < n.size(); i++) {
    for (long long j = i + 1; j < n.size(); j++) {
      if (i != 0) {
        ans += 81;
        continue;
      }
      long long f = n[0] - '0';
      ans += (f - 1) * 9;
      bool flag = 1;
      for (long long y = 1; y < j; y++) {
        if (n[y] != '0') flag = 0;
      }
      if (!flag) {
        ans += 9;
        continue;
      }
      long long s = n[j] - '0';
      ans += s;
    }
  }
  cout << ans << endl;
}
void solve3() {
  long long ans = 0;
  for (long long i = 0; i < n.size(); i++) {
    for (long long j = i + 1; j < n.size(); j++) {
      for (long long l = j + 1; l < n.size(); l++) {
        if (i != 0) {
          ans += 729;
          continue;
        }
        long long f = n[0] - '0';
        ans += (f - 1) * 81;
        bool flag = 1;
        for (long long y = 1; y < j; y++) {
          if (n[y] != '0') flag = 0;
        }
        if (!flag) {
          ans += 81;
          continue;
        }
        long long s = n[j] - '0';
        ans += (s - 1) * 9;
        flag = 1;
        for (long long y = j + 1; y < l; y++) {
          if (n[y] != '0') flag = 0;
        }
        if (!flag) {
          ans += 9;
          continue;
        }
        long long t = n[l] - '0';
        ans += t;
      }
    }
  }
  cout << ans << endl;
}
signed main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  cout.tie(0);
  ;
  cin >> n >> k;
  if (k == 1) {
    solve1();
  } else if (k == 2) {
    solve2();
  } else {
    solve3();
  }
  return 0;
}
