#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n;
  cin >> k;
  int ans = 0;
  if (k == 1) {
    if (n < 10) {
      ans = n;
    } else {
      ans = 9 + (n / 10);
    }
  } else if (k == 2) {
    if (n >= 11) {
      for (int i = 0; i <= n; ++i) {
        int r;
        int i_t = i;
        vector<int> nums;
        while (i_t != 0) {
          r = i_t % 10;
          i_t = i_t / 10;
          if (r != 0) nums.push_back(r);
        }
        if (nums.size() == 2) ans++;
      }
    }
  } else if (k == 3) {
    if (n >= 111) {
      for (int i = 0; i <= n; ++i) {
        int r;
        int i_t = i;
        vector<int> nums;
        while (i_t != 0) {
          r = i_t % 10;
          i_t = i_t / 10;
          if (r != 0) nums.push_back(r);
        }
        if (nums.size() == 3) ans++;
      }
    }
  }
  cout << ans << endl;
}
