#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll inf = (ll)1e9 + 7;
const ll maxn = (ll)6e5 + 7;
const ll lmaxn = (ll)6e6 + 7;
const ll linf = (ll)2e18 + 7;
const ld eps = ld(1e-11);
const ll dx[] = {-1, 0, 0, 1};
const ll dy[] = {0, -1, 1, 0};
ll gcd(ll a, ll b) {
  while (b) a %= b, swap(a, b);
  return a | b;
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll n, ans;
string a;
ll d[70][70], p[70][70];
ll gg(ll x, ll y) {
  ll ee = 1;
  for (ll i = 1; i <= y; ++i) ee *= x;
  return ee;
}
int main() {
  cin >> n >> a;
  reverse(a.begin(), a.end());
  for (ll i = 0; i <= (ll)a.size(); ++i) {
    for (ll j = 0; j <= (ll)a.size(); ++j) {
      d[i][j] = 0;
    }
  }
  d[0][0] = 1;
  for (ll i = 1; i <= (ll)a.size(); ++i) {
    for (ll j = 1; j <= (ll)a.size(); ++j) {
      for (ll k = i; k >= 1; --k) {
        ll good = (a[i - 1] != '0' || (i - k + 1 == 1)), num = 0;
        for (ll e = i; e >= k; --e) {
          num *= 10;
          num += (a[e - 1] - '0');
          if (num > n) {
            good = 0;
            break;
          }
        }
        good = good & (num < n);
        if (good && d[k - 1][j - 1])
          d[i][j] |= 1, p[i][j] = (!p[i][j] ? k - 1 : max(p[i][j], k - 1));
      }
    }
  }
  ll idx = 0;
  for (ll i = 1; i <= (ll)a.size(); ++i) {
    if (d[(ll)a.size()][i]) {
      idx = i;
      break;
    }
  }
  ll now = (ll)a.size();
  while (idx) {
    ll pe = p[now][idx] + 1;
    ll num = 0;
    for (ll i = now; i >= pe; --i) num *= 10, num += (a[i - 1] - '0');
    ans += num * gg(n, idx - 1);
    now = pe - 1;
    --idx;
  }
  cout << ans;
  return 0;
}
