#include <bits/stdc++.h>
using namespace std;
const int N = 111, INF = 1e9 + 7;
int k, n, f[N];
long long Pw[N];
char s[N];
void Enter() {
  scanf("%d", &k);
  scanf("%s", s + 1);
  n = strlen(s + 1);
}
int calc(int l, int r) {
  if (l == r && s[l] == '0') return 0;
  if (s[l] == '0') return INF;
  long long res = 0;
  for (int i = l; i <= r; ++i) {
    res = res * 10 + s[i] - '0';
    res = min(res, 1ll * INF);
  }
  return res;
}
void Process() {
  if (s == "0") {
    puts("0");
    return;
  }
  memset(f, INF, sizeof f);
  Pw[0] = 1;
  for (int i = 1; i <= n; ++i) Pw[i] = Pw[i - 1] * k;
  f[n + 1] = 0;
  for (int i = n; i >= 1; --i)
    for (int j = i; j <= n; ++j)
      if (calc(i, j) < k) {
        f[i] = min(f[i], f[j + 1] + 1);
      }
  long long res = 0;
  for (int i = 1; i <= n;) {
    int j = i;
    while (j <= n && f[i] != f[j + 1] + 1) j++;
    long long cur = 0;
    for (int o = i; o <= j; ++o) cur = cur * 10 + s[o] - '0';
    res = res + cur * Pw[f[j + 1]];
    i = j + 1;
  }
  printf("%I64d", res);
}
int main() {
  Enter();
  Process();
  return 0;
}
