#include <stdio.h>
#include <string.h>
int main() {
static char s[128];
static long long dp[128];
int n, i, j, l;
long long a, b;
scanf(“%d”, &n);
scanf(“%s”, s);
l = strlen(s);
for (i = 0; i < l; i++)
dp[i] = 1e18 + 1;
for (i = 0; i < l; i++)
for (j = i, a = s[i] – ‘0’, b = 1; j >= 0 && a < n && b < n; j–) {
double x = (j == 0 ? (double) a : (double) dp[j – 1] * n + a);
if ((a >= b || i – j + 1 == 1) && dp[i] > x)
dp[i] = x;
b *= 10;
a += j == 0 ? 0 : b * (s[j – 1] – ‘0’);
}
printf(“%lld\n”, dp[l – 1]);
return 0;
}