#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long ncr[1004][1004] = {0};
void precompute() {
  for (int i = 0; i <= 1002; i++) {
    ncr[i][0] = 1;
  }
  for (int i = 1; i <= 1002; i++) {
    for (int j = 1; j <= 1002; j++) {
      ncr[i][j] = (ncr[i - 1][j - 1] + ncr[i - 1][j]) % MOD;
    }
  }
}
int cal(int n) {
  int p, rem, x;
  x = n;
  int tot = 0;
  while (x) {
    tot += x % 2;
    x /= 2;
  }
  return tot;
}
int main() {
  precompute();
  long long i, j, m, dp[1005], k;
  string n;
  for (i = 2; i <= 1002; i++) {
    dp[i] = dp[cal(i)] + 1;
  }
  cin >> n;
  cin >> k;
  if (k == 0) {
    cout << 1 << "\n";
    return 0;
  }
  long long ans = 0, nones = 0, cnt = 0;
  for (i = 0; i < n.size(); i++) {
    if (n[i] == '0') continue;
    cnt++;
    for (j = max(nones, 1LL); j < 1002; j++) {
      if (dp[j] == k - 1) {
        ans = (ans + ncr[n.size() - i - 1][j - nones]) % MOD;
        if (i == 0 && k == 1) {
          ans = (ans + MOD - 1) % MOD;
        }
      }
    }
    nones++;
  }
  if (dp[cnt] == k - 1) ans = (ans + 1) % MOD;
  cout << ans % MOD;
}
