#include <bits/stdc++.h>
using namespace std;
char s[1002];
int need[1002];
int dp[1002][1002], C[1002][1002];
int k;
int check(int x) {
  if (x == 1) return 0;
  int ret = 0;
  while (1) {
    int c = 0;
    while (x) {
      if (x & 1) ++c;
      x >>= 1;
    }
    ++ret;
    if (c == 1) break;
    x = c;
  }
  return ret;
}
int add(int ones) {
  memset(dp, 0, sizeof(dp));
  int len = strlen(s);
  dp[len - 1][0] = 1;
  dp[len - 1][1] = (s[len - 1] == '1');
  for (int i = len - 2; i >= 0; i--) {
    for (int j = ones; j >= 0; j--) {
      if (s[i] == '1') {
        dp[i][j + 1] = (dp[i][j + 1] + dp[i + 1][j]);
        dp[i][j] = (dp[i][j] + C[len - i - 1][j]);
        if (dp[i][j] > 1000000007) dp[i][j] %= 1000000007;
        if (dp[i][j + 1] > 1000000007) dp[i][j + 1] %= 1000000007;
      } else {
        dp[i][j] = (dp[i][j] + dp[i + 1][j]);
        if (dp[i][j] > 1000000007) dp[i][j] %= 1000000007;
      }
    }
  }
  return dp[0][ones];
}
int main() {
  for (int i = 1; i <= 1000; i++) need[i] = check(i);
  C[0][0] = 1;
  for (int i = 1; i <= 1000; i++) {
    C[i][0] = 1;
    C[i][i] = 1;
    for (int j = 1; j < i; j++)
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000000007;
  }
  scanf("%s%d", s, &k);
  if (k > 5) return printf("0"), 0;
  if (k == 0) return printf("1"), 0;
  if (k == 1) return printf("%d", strlen(s) - 1), 0;
  --k;
  int ans = 0;
  for (int i = 1; i <= 1000; i++)
    if (need[i] == k) {
      ans = (ans + add(i)) % 1000000007;
    }
  printf("%d", ans);
  return 0;
}
