#include <bits/stdc++.h>
using namespace std;
char s[100];
int main() {
  long long n;
  scanf("%I64d%s", &n, s);
  int len = strlen(s);
  int digit_count = 0, n0 = n;
  while (n0) {
    digit_count++;
    n0 /= 10;
  }
  long long ans = 0;
  long long tot_pow = 1;
  for (int r = len - 1; r >= 0;) {
    long long cur = s[r] - '0';
    long long pwr = 10;
    int l = r;
    int last_non_zero = r;
    while (l > 0 && cur + (s[l - 1] - '0') * pwr < n &&
           r - l + 1 < digit_count) {
      if (s[l - 1] - '0') last_non_zero = l - 1;
      cur += (s[l - 1] - '0') * pwr;
      pwr *= 10;
      l--;
    }
    if (!cur) {
      r--;
    } else {
      r = last_non_zero - 1;
    }
    ans += cur * tot_pow;
    tot_pow *= n;
  }
  printf("%I64d\n", ans);
}
