#include using namespace std; using str=string; str to_s(int n,int b){ str s; for(;n>0;n/=b){ s=char(n%b+'0')+s; } return s; } int main(){cin.tie(0);ios::sync_with_stdio(false); int B;cin>>B; str D;cin>>D; int n; for(n=1;;++n){ str s=to_s(n-1,B); if(D.size()=0;--i){ if(D[i]>=B+'0'){ D[i]-=B; if(i){ ++D[i-1]; }else{ D=char('1')+D; } } } str r; int x=0; bool b=false; for(int i=0;i