#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long C[1005][1005], dp[1005], k, cnt;
string s;
int getbit(int x) {
  int ans = 0;
  while (x) {
    int tmp = x & -x;
    ans++;
    x ^= tmp;
  }
  return ans;
}
void Comb() {
  for (int i = 0; i <= 1000; i++) C[i][0] = 1;
  for (int i = 1; i <= 1000; i++)
    for (int j = 1; j <= i; j++)
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
  return;
}
long long solve(int N) {
  dp[1] = 0;
  long long ans = 0;
  for (int i = 2; i <= 1000; i++) dp[i] = dp[getbit(i)] + 1;
  for (int i = 0; i < N; i++) {
    if (s[i] == '0') continue;
    for (int j = max(1ll, cnt); j < N; j++) {
      if (dp[j] == k - 1) ans = (ans + C[N - i - 1][j - cnt]) % MOD;
    }
    cnt++;
  }
  if (k == 1) --ans;
  if (dp[cnt] == k - 1) ans = (ans + 1) % MOD;
  return ans;
}
int main() {
  cin >> s >> k;
  if (k == 0) {
    return puts("1"), 0;
  }
  int N = s.size();
  Comb();
  cout << solve(N) << endl;
  return 0;
}
