#include <bits/stdc++.h>
using namespace std;
int binary(int bina) {
  int ans = 0;
  for (int i = 0; bina > 0; i++) {
    ans = ans + (bina % 2) * pow(10, i);
    bina = bina / 2;
  }
  return ans;
}
unsigned GetDigit(unsigned num) { return log10(num) + 1; }
int digit(int N) {
  while (N >= 10) {
    int tmp{};
    while (N > 0) {
      tmp += (N % 10);
      N /= 10;
    }
    N = tmp;
  }
  return N;
}
int main() {
  int n, k;
  int count = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    if (GetDigit(binary(i + 1)) - digit(binary(i + 1)) == k) {
      count++;
    }
  }
  cout << count;
}
