#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    char S, T;
    cin >> S >> T;

    if(S=='Y'){
        char s = toupper(T);
        cout <<s<< endl;
    }else{
        cout << T << endl;
    }
}
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
using ll = long long;
struct Edge
{
    ll to;
    ll cost;
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, ll>;
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), v.end()
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = LLONG_MAX;
const int MAX = 510000;
bool graph[nmax][nmax];
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;

    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

bool is_sum_overflow(ll a, ll b)
{
    if (a < LLONG_MAX / 2)
    {
        if (b < LLONG_MAX / 2)
            return false;
        else
            return ((b - LLONG_MAX / 2) + a > LLONG_MAX / 2);
    }
    else
    {
        if (b < LLONG_MAX / 2)
            return true;
        else
            return ((a - LLONG_MAX / 2) + b > LLONG_MAX / 2);
    }
}
bool isOK(ll mid, string X, ll M)
{
    ll sum = 0;
    for (int i = X.size() - 1; i >= 0; i--)
    {

        ll tmp = X[i] - '0';
        for (int j = 0; j < X.size() - i - 1; j++)
        {
            ll prev = tmp;

            if (tmp >= LLONG_MAX / mid)
            {
                // 多分オーバーフローしたからMは超えてる
                return true;
            }
            tmp *= mid;
        }

        if (is_sum_overflow(sum, tmp))
        {
            // overflow下からMは超えてる
            return true;
        }
        sum += tmp;
    }

    if (sum > M)
    {

        return true;
    }
    else
    {
        return false;
    }
}

void solve(std::string X, long long M)
{
    if (X.length() == 1)
    {
        ll d = (X[0] - '0');
        if (d <= M)
            cout << 1 << endl;
        else
            cout << 0 << endl;
        return;
    }
    ll d = 0;
    for (int i = 0; i < X.size(); i++)
    {
        d = max(d, (ll)(X[i] - '0'));
    }
    ll left = d;
    ll right = 1e18;
    right += 10;

    while (right - left > 1)
    {
        ll mid = left + (right - left) / 2;
        if (isOK(mid, X, M))
            right = mid;
        else
            left = mid;
    }
    cerr << left << endl;
    cout << left - (d + 1) + 1 << endl;
}

int main()
{

    std::string X;
    std::cin >> X;
    long long M;
    scanf("%lld", &M);
    solve(X, M);
    return 0;
}
