#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>
using namespace std;
long long mypow(long long a,long long b)
{
long long ans=1;
for(int i=0; i<b; i++)
{
ans*=a;
}
return ans;
}
int main()
{
char s[100];
long long n,a;
while(~scanf("%I64d %s",&n,s))
{
int k=strlen(s);
for(int i=0; i<k/2; i++)
{
swap(s[i],s[k-1-i]);
}
long long m=n;
int t=0;
while(m>0)
{
m/=10;
t++;
}
long long kk=0,as=0,pw=0,tot=0,w[1000],ans=0;
for(int i=0; i<k; i++)
{
as+=(s[i]-'0')*mypow(10,kk);
kk++;
if(kk==t)
{
while(s[i]=='0'&&kk>1)
{
i--;
kk--;
}
if(as<n)
w[tot++]=as;
else
{
w[tot++]=as-mypow(10,kk-1)*(s[i]-'0');
kk--;
i--;
while(s[i]=='0'&&kk>1)
{
i--;
kk--;
}
}
as=0;
kk=0;
}
}
w[tot++]=as;
for(int i=0;i<tot;i++)
{
ans+=w[i]*mypow(n,pw);
pw++;
}
printf("%I64d\n",ans);
}
return 0;
}