#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>
#include<map>
#include<cassert>

using namespace std;

#define ll long long
#define reps(i, a, b) for(int i = a; i < b; i++)
#define rreps(i, a, b) for(int i = a-1; i >= b; i--)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) rreps(i, n, 0)
#define P pair<int, int>
#define vec vector<int>
#define mat vector<vec>

const ll mod = 1000000007;
const ll INF = 1001001001001001001;

string x;
ll m;
vector<ll> s;

bool f(ll b){
    vector<ll> y;
    ll a = m;
    while(a > 0){
        y.push_back(a%b);
        a /= b;
    }
    reverse(y.begin(), y.end());

    // cout << b << endl;
    // rep(i, s.size()){
    //     cout << s[i] << " ";
    // }cout << endl;   
    // rep(i, y.size()){
    //     cout << y[i] << " ";
    // }cout << endl;
    // cout << endl;

    if(y.size() > s.size()) return true;
    else if(y.size() == s.size()){
        rep(i, y.size()){
            if(y[i] > s[i]) return true;
            else if(y[i] < s[i]) return false;
        }
        return true;
    }else return false;
}

int main(){
    cin >> x >> m;
    int k = 0;
    int mx = 1;
    while(x[k] != 0) {
        int c = x[k]-'0';
        mx = max(mx, c);
        k++;
        s.push_back(c);
    }

    if(k == 1){
        int c = x[0]-'0';
        if(c > m) cout << 0 << endl;
        else cout << 1 << endl;
        return 0;
    }
    // rep(i, s.size()){
    //     cout << s[i];
    // }cout << endl;

    ll l = 1, r = INF;
    while(l < r - 1){
        ll mid = (l+r) / 2;
        if(f(mid)){
            l = mid;
        }else{
            r = mid;
        }
    }
    l = min(l, (ll)1000000000000000000);
    // cout << l << " " << mx << endl;
    cout << max((ll)0, l - mx) << endl;
}
//#define local
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;
#ifdef local
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(10);
    ll n; cin >> n;
    string s; cin >> s;
   for(ll i=2;i<s.size();i++){
       if(s[i-2]=='f'&&s[i-1]=='o'&&s[i]=='x'){
           s.erase(i-2,3);
           i-=3;
       }
   }
   cout << s.size() << endl;
}