#include <bits/stdc++.h>
using namespace std;
long long n;
char s[65];
long long b[10] = {1,      10,      100,      1000,      10000,
                   100000, 1000000, 10000000, 100000000, 1000000000};
int main() {
  scanf("%I64d", &n);
  scanf("%s", s);
  int len = strlen(s), pl = len - 1, lar, lapl = len;
  long long ans = 0, now = 1ll, tp = 0ll;
  while (pl >= 0) {
    long long rp = tp + (s[pl] - '0') * b[lapl - pl - 1];
    if (rp >= n || lapl - pl - 1 == 9) {
      ans += tp * now;
      tp = 0ll;
      now *= n;
      pl = lar;
      lapl = pl;
    } else {
      if (s[pl] != '0' || pl == lapl - 1) {
        lar = pl;
      }
      tp = rp;
    }
    pl--;
  }
  ans += tp * now;
  printf("%I64d", ans);
  return 0;
}
