#include <bits/stdc++.h>
const int _ML = 220;
const char _inpf[] = "";
const char _outf[] = "";
#pragma GCC optimize("O3")
using namespace std;
const double PI = 3.14159265358979323846;
mt19937 rd(228);
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {
  _out << _p.first << ' ' << _p.second;
  return _out;
}
template <typename T, typename U>
inline istream &operator>>(istream &_in, pair<T, U> &_p) {
  _in >> _p.first >> _p.second;
  return _in;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const vector<T> &_v) {
  if (_v.empty()) {
    return _out;
  }
  _out << _v.front();
  for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline istream &operator>>(istream &_in, vector<T> &_v) {
  for (auto &_i : _v) {
    _in >> _i;
  }
  return _in;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const set<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const multiset<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const unordered_set<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const unordered_multiset<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const map<T, U> &_m) {
  if (_m.empty()) {
    return _out;
  }
  _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')';
  for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) {
    _out << ", (" << _it->first << ": " << _it->second << ')';
  }
  return _out;
}
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const unordered_map<T, U> &_m) {
  if (_m.empty()) {
    return _out;
  }
  _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')';
  for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) {
    _out << ", (" << _it->first << ": " << _it->second << ')';
  }
  return _out;
}
const long long M = 1000 * 1000 * 1000 + 7;
const int N = 1002;
int dp[N];
long long f[N];
long long fi[N];
long long bp(long long a, long long b) {
  long long r = 1;
  while (b) {
    if (b & 1) {
      r = (r * a) % M;
    }
    a = (a * a) % M;
    b >>= 1;
  }
  return r;
}
inline void mainFunction() {
  f[0] = 1;
  fi[0] = 1;
  for (int i = 1; i < N; ++i) {
    f[i] = f[i - 1] * i % M;
    fi[i] = bp(f[i], M - 2);
  }
  dp[0] = -228;
  dp[1] = 0;
  for (int i = 2; i < N; ++i) {
    dp[i] = dp[__builtin_popcount(i)] + 1;
  }
  string s;
  cin >> s;
  int k;
  cin >> k;
  if (k == 0) {
    cout << 1 << '\n';
    return;
  }
  long long ans = 0;
  int pl = 0;
  for (int i = 0; i < (int)(s).size(); ++i) {
    if (s[i] == '0') {
      continue;
    }
    int j = (int)(s).size() - i - 1;
    for (int l = 0; l <= j; ++l) {
      int sum = pl + l;
      if (dp[sum] + 1 == k) {
        ans = ((ans + f[j] * fi[j - l] % M * fi[l]) % M);
      }
    }
    ++pl;
  }
  if (dp[count((s).begin(), (s).end(), '1')] + 1 == k) {
    ++ans;
  }
  if (k == 1) {
    --ans;
  }
  ans = (ans % M + M) % M;
  cout << ans << '\n';
}
int main() {
  if (_inpf[0] != '\0') assert(freopen(_inpf, "r", stdin) != nullptr);
  if (_outf[0] != '\0') assert(freopen(_outf, "w", stdout) != nullptr);
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << setprecision(228);
  mainFunction();
}
