#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <fstream>
#include <cmath>

using namespace std;

typedef unsigned long long ll;
const ll INF=18000000000000000000ULL;


map<int,int> prime_decompos(int a){
	map<int,int> res;
	for(int i=2;i*i<=a;i++){
		if(a%i==0){
			res[i]++;
			a/=i;
			i--;
		}
	}
	if(a!=1)res[a]++;
	return res;
}

int main(){
	int n;
	ll m;
	string str;
	while(cin>>n>>str&&!(n==0&&str=="0")){
		ll mul=1;
		m=0;
		for(int i=str.size()-1;i>=0;i--){
			ll a=str[i]-'0';
			if(str[i]>='A'&&str[i]<='Z')a=10+str[i]-'A';
			m+=a*mul;
			mul*=n;
		}
		if(m==0){
			cout<<0<<endl;
			continue;
		}
		map<int,int> np=prime_decompos(n);
		ll res=INF;
		for(map<int,int>::iterator it=np.begin();it!=np.end();it++){
			ll a=it->first;
			int b=it->second;
			ll cnt=0;
			int loop=(log((long double)m)/log((long double)a)+(1e-10));
			while(loop--){
				cnt+=(m/a);
				a*=it->first;
			}
			res=min(res,cnt/b);
		}
		cout<<res<<endl;
	}

	return 0;
}