#include <bits/stdc++.h>
using namespace std;
const int N = 1234;
const int mod = 1000000007;
int k, len, st[N], dp[2][N][N];
char s[N];
int solve(bool less, int i, int t) {
  if (i == len) return (t && st[t] == k - 1);
  int &r = dp[less][i][t];
  if (r == -1) {
    r = 0;
    if (s[i] == '1') {
      r += solve(less, i + 1, t + 1);
      r += solve(1, i + 1, t);
    } else {
      if (less) r += solve(less, i + 1, t + 1);
      r += solve(less, i + 1, t);
    }
    r %= mod;
  }
  return r;
}
int main() {
  scanf("%s%d", s, &k);
  len = strlen(s);
  if (k == 0) return printf("1\n"), 0;
  for (int i = 2; i < N; i++) st[i] = 1 + st[__builtin_popcount(i)];
  memset(dp, -1, sizeof dp);
  int ans = solve(0, 0, 0);
  if (k == 1) ans = (ans + mod - 1) % mod;
  printf("%d\n", ans);
  return 0;
}
