#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long n, res, num, mult, fac, newn;
  bool inz;
  string s;
  scanf("%I64d", &n);
  cin >> s;
  fac = 1;
  mult = 1;
  res = 0;
  num = 0;
  for (int i = s.length() - 1; i >= 0; i--) {
    inz = false;
    if (s[i] == '0') {
      long long mm = 1;
      int counter = 0;
      while (s[i] == '0') {
        i--;
        counter++;
      }
      while (counter > 9) {
        fac *= n;
        counter--;
        inz = true;
      }
      while (counter > 0) {
        mm *= 10;
        counter--;
      }
      if (num + (s[i] - '0') * mm * mult < n) {
        num = num + (s[i] - '0') * mm * mult;
        mult *= mm;
        mult *= 10;
        if (i == 0) {
          res += num * fac;
        }
        i--;
      } else {
        res += num * fac;
        if ((fac != 1 || num != 0) && !inz) {
          fac *= n;
        }
        num = (s[i] - '0') * mm;
        mult = mm;
        while (num >= n) {
          fac *= n;
          mult /= 10;
          num /= 10;
        }
        num = 0;
      }
      i++;
      continue;
    }
    newn = (s[i] - '0') * mult;
    mult *= 10;
    if (newn + num < n) {
      num += newn;
    } else {
      res += num * fac;
      fac *= n;
      mult = 10;
      num = s[i] - '0';
    }
    if (i == 0) {
      res += num * fac;
    }
  }
  printf("%I64d", res);
  return 0;
}
