#include<bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i) < (n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i) < (n);(i)++)


using namespace std;
using ll = long long;
using ld = long double;

template<typename T>
bool chmax(T &a,const T &b) {if(a < b) {a = b;return true;}return false;}
template<typename T>
bool chmin(T &a,const T &b) {if(a > b) {a = b;return true;}return false;}

ll pow(ll x,ll n){
	ll res = 1;
	while(n > 0){
		if(n & 1) res = res * x;
		x = x*x;
		n >>= 1;
	}
	return res;
}

bool is_prime(ll n){
	if(n == 0 || n == 1) return false;
	else if(n == 2 || n == 3 || n == 5) return true;
	else if(n % 2 == 0 || n % 3 == 0 || n % 5 == 0) return false;
	else{
		for(ll i=7;i * i <= n;i+=2){
			if(n % i == 0) return false;
		}
	}
	return false;
}

int main(){
	ll n;
	cin >> n;

	set<ll> s;

	for(ll a=2;a * a <= n;a++){
		ll x = a*a;
		while(x <= n){
			s.insert(x);
			x *= a;
		}
	}

	ll ans = n - s.size();

	cout << ans << endl;
	return 0;
}
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

// AtCoder
// #include <atcoder/all>
// using namespace atcoder;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...)
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;
int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string x; cin >> x;
    int n = x.length();
    ll m; cin >> m;
    if (x.length() == 1) {
        if ((int)(x[0] - '0') <= m) cout << 1 << "\n";
        else cout << 0 << "\n";
    } else {
        int soko = (int)(*max_element(all(x)) - '0') + 1;
        ll ok = soko - 1, ng = m + 1;
        eprintf("%lld %lld\n", ok, ng);
        while (abs(ok - ng) > 1) {
            __int128_t med = (ok + ng) / 2;
            __int128_t y = 0, m_tmp = m;
            eprintf("%lld\n", (ll)med);
            reprev (i, n) {
                m_tmp -= x[i] - '0';
                if (m_tmp < 0) {
                    ng = med;
                    goto end_loop;
                }
                m_tmp /= med;
            }
            ok = med;
            end_loop:;
        }
        cout << ok - soko + 1 << "\n";
    }

    return 0;
}