#include <bits/stdc++.h>
using namespace std;

int main()
{
    long long n;

    cin >> n;

    long long left = 0;
    long long right = 2e9;

    while (right - left > 1)
    {
        long long x = (left + right) / 2;
        if ((x * (x + 1)) / 2 <= n + 1)
        {
            left = x;
        }
        else
        {
            right = x;
        }
    }

    cout << n + 1 - left << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

string X;
ll M;

bool solve(ll mid) {
   ll res = 0;
   ll multiply = 1;
   for(ll i = X.length() - 1; i >= 0; i--) {
       ll x = (X.at(i) - '0');
       if(multiply > (1e18 / x)) {
           return false;
       }
       if(res > 1e18 - x * multiply) {
           return false;
       }
       res += x * multiply;
       if(i != 0) {
           if(multiply > 1e18 / mid) {
               return false;
           }
           multiply *= mid;
       }
   }
   return (res <= M);
}

int main() {
    cin >> X;
    cin >> M;
    if(X.length() == 1) {
        ll num = X.at(0) - '0';
        if(num <= M) {
           cout << 1 << endl;
           return 0;
        }
        cout << 0 << endl;
        return 0;
    }
    ll d = 0;
    for(const char &c : X) {
        d = max(d, (ll)(c - '0'));
    }
    ll ok = d;
    ll ng = (long double)(1e18) + 1;
    while(abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if(solve(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << ok - d << endl;
    return 0;
}