import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

long MOD = 10^^9 + 7;

void main() {
    auto N = readln.chomp;
    auto K = readln.chomp.to!int;
    auto dp = new int[](1001);
    dp[1] = 1;

    for (int i = 2; i <= 1000; ++i) {
        dp[i] = dp[i.popcnt] + 1;
    }

    auto dp2 = new long[][][](N.length+1, N.length+1, 2);
    dp2[0][0][0] = 1;

    foreach (i; 0..N.length) {
        foreach (j; 0..N.length+1) {
            foreach (k; 0..2) {
                int digit = (k || N[i] == '1') ? 2 : 1;
                foreach (d; 0..digit) {
                    if (j+d <= N.length)
                        (dp2[i+1][j+d][k||(d < N[i]-'0')] += dp2[i][j][k]) %= MOD;
                }
            }
        }
    }

    long ans = 0;
    foreach (i; 1..N.length+1) {
        if (dp[i] == K) {
            (ans += dp2[N.length][i][0]) %= MOD;
            (ans += dp2[N.length][i][1]) %= MOD;
        }
    }

    if (K == 1) {
        ans -= 1;
        ans %= MOD;
    } else if (K == 0) {
        ans = 1;
    }

    ans.writeln;
}
