#include <bits/stdc++.h>
using namespace std;
long long quick(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans *= a;
    a *= a;
    b >>= 1;
  }
  return ans;
}
char c[100];
int main() {
  long long x, n, xx;
  while (~scanf("%I64d%s", &x, c)) {
    int len1 = 0;
    xx = x;
    while (xx) {
      len1++;
      xx /= 10;
    }
    int len2 = strlen(c);
    long long wei = 0;
    long long tp = 0;
    long long ans = 0;
    long long k = -1;
    for (int i = len2 - 1; i >= 0; i--) {
      tp += 1ll * (c[i] - '0') * quick(10, ++k);
      if (len2 - i == len1 || i == 0) {
        if (tp >= x) tp -= 1ll * (c[i] - '0') * quick(10, k), i++;
        while (c[i] == '0' && i < len2 - 1) {
          i++;
        }
        len2 = i;
        ans += 1ll * tp * quick(x, wei++);
        tp = 0;
        k = -1;
      }
    }
    printf("%I64d\n", ans);
    memset(c, 0, sizeof(c));
  }
  return 0;
}
