#include <cstdio>
int main(){
int radix = 0;
int src = 0;
scanf("%d%d", &radix, &src);
int res = src % 10;
src /= 10;
int multiple = radix;
while (src > 0){
res += src % 10 * multiple;
src /= 10;
multiple *= radix;
}
printf("%d\n", res);
return 0;
}