#include using namespace std; int b; string d; main() { cin>>b>>d; int x; for(x=1;x0&&id>=0) { if(d[id]-48>=sub%b) { d[id]-=sub%b; } else { d[id]=d[id]-sub%b+b; sub+=b; } sub/=b; id--; } if(sub>0) { for(int i=0;i<=d.size()-x;i++)sub*=b; sub-=x*(b-1); int id=d.size()-x; while(sub>0) { if(d[id]-48>=sub%b)d[id]-=sub%b; else { d[id]=d[id]-sub%b+b; sub+=b; } sub/=b; id--; } break; } } string ans=""; int carry=0; for(int i=0;i0;i--) { carry=carry*b+d[d.size()-i]-48; ans+=48+carry/x+(i==x); int t=carry/x+(i==x); if(t<0||t>9)return 1; carry%=x; } if(carry>0) { int id=ans.size()-1; while(ans[id]-48==b-1)ans[id--]=48; ans[id]++; } else { int id=ans.size()-1; while(ans[id]-48==0)ans[id--]=48+b-1; ans[id]--; } cout<