#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define rep(i, n) for(int i=0;i<n;i++)
#define all(i, v) for(auto& i : v)
typedef long long ll;
using namespace std;
const ll mod=998244353, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;



///////// combination
const ll N = 200007;
ll fac[N],finv[N],inv[N];
void cominit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<N;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll com(ll n,ll k){
    if(n<k)return 0;
    if(n<0 || k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

ll COM(ll n, ll k){
    if(n < k or n < 0 or k < 0) return 0;
    k = min(n - k, k);
    ll ret = finv[k]; // for() modpow(a, mod - 2);
    for(ll r=n-k+1;r<=n;r++){
        ret *= r;
        ret %= mod;
    }
    return ret;
}





///////modint
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};

long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}




int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    cominit();
    ll n, m;
    cin >> n >> m;
    vector<vector<mint> > dp(15, vector<mint> (m + 1, mint(0)));
    rep(i, 15){
        if(i == 0){
            for(ll j=0;j<=m;j+=2) dp[i][j] = mint(com(n, j));
            continue;
        }
        ll p = modpow(2LL, ll(i));
        for(ll j=0;j<=m;j+=2){
            for(ll k=0;k<=n;k+=2){
                if(k*p > j) break;
                dp[i][j] += dp[i - 1][j - k*p] * mint(com(n, k));
            }
        }
    }
    cout << dp[14][m].x << endl;
    return 0;
}




#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e18;
int inf = 1e9;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string s; cin >> s;
    ll m; cin >> m;

    ll d = 0;
    for (auto &e: s) d = max(d, ll(e - '0'));
    d++;

    if (s.size() == 1) {
        if (s[0] - '0' <= m) print(1);
        else print(0);
        return 0;
    } else {
        auto check = [&](ll b) -> bool {
            ll cur = 0;
            for(auto &e: s) {
                if (cur > 0) {
                    ld val = log10(cur) + log10(b);
                    if (val >= 18.1) return false;
                }
                cur *= b;
                cur += e - '0';
            }

            return cur <= m;
        };

        if (not check(d)) {
            print(0);
            return 0;
        }

        ll ok = d, ng = m + 5;
        while(ng - ok > 1) {
            ll mid = (ok + ng) / 2;
            if (check(mid)) ok = mid;
            else ng = mid;
        }

        print(ok - d + 1);
    }

}
