#include <bits/stdc++.h>
using namespace std;
long long int fact[1000007];
void precall() {
  long long int i;
  fact[0] = 1;
  for (i = 1; i < 1000007; i++) fact[i] = (fact[i - 1] * i) % 1000000007;
}
long long int power(long long int a, long long int p) {
  if (p == 0) return 1;
  if (p == 1) return a;
  if (p % 2 == 0) {
    long long int c = power(a, p / 2);
    long long int d = (c * c) % 1000000007;
    return d;
  } else {
    long long int c = power(a, p - 1);
    long long int d = (c * a) % 1000000007;
    return d;
  }
}
long long int ncr(long long int n, long long int r) {
  long long int ans, b;
  ans = fact[n];
  b = (fact[n - r] * fact[r]) % 1000000007;
  ans = (ans * power(b, 1000000007 - 2)) % 1000000007;
  return ans;
}
bool check1(int n, int pos) { return (bool)(n & (1 << pos)); }
long long int ar1[1007];
char s1[1007];
long long int l1, k1;
long long int dp[1007];
long long int f1(long long int n1) {
  if (dp[n1] != -1) return dp[n1];
  if (n1 == 1) return dp[n1] = 0;
  long long int a, b, c, d, i, j, k, l, m;
  l = 0;
  for (i = 0; i < 29; i++) {
    if (check1(n1, i) == 1) l++;
  }
  return dp[n1] = 1 + f1(l);
}
int main() {
  precall();
  long long int a, b, c, d, i, j, k, l, m, n;
  memset(dp, -1, sizeof(dp));
  for (i = 1007 - 1; i > 0; i--) {
    if (dp[i] != -1) continue;
    dp[i] = f1(i);
  }
  k = 0;
  for (i = 1; i <= 13; i++) {
    if (dp[i] == 2) k++;
  }
  dp[0] = 0;
  scanf("%s", s1);
  scanf("%lld", &k1);
  l1 = strlen(s1);
  if (l1 == 1) {
    if (k1 == 0)
      cout << "1" << endl;
    else
      cout << "0" << endl;
    return 0;
  }
  if (k1 == 0) {
    cout << "1" << endl;
    return 0;
  }
  if (k1 == 1) {
    cout << l1 - 1 << endl;
    return 0;
  }
  for (i = 0; i < l1; i++) ar1[i] = s1[i] - 48;
  long long int ans = 0;
  for (i = 1; i < l1; i++) {
    if (dp[i] == k1 - 1) {
      a = ncr(l1 - 1, i);
      ans = (ans + a) % 1000000007;
    }
  }
  l = 1;
  for (i = 1; i < l1; i++) {
    if (ar1[i] == 1) {
      for (j = 0; j <= l1 - i; j++) {
        if (dp[l + j] == k1 - 1) {
          a = ncr(l1 - i - 1, j);
          ans = (ans + a) % 1000000007;
        }
      }
      l++;
    }
  }
  if (dp[l] == k1 - 1) ans++;
  cout << ans << endl;
  return 0;
}
