#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  string k;
  cin >> n >> k;
  long long now = 0, p = k.length() - 1, base = 1, ans = 0;
  while (p >= 0) {
    long long _base = 1;
    do {
      now += ((k[p--] - '0') * _base);
      _base *= 10;
    } while (now < n && p >= 0 && _base <= n * 10);
    long long tmp = now;
    long long __base = 10;
    while (tmp /= 10) __base *= 10;
    long long t = _base / __base;
    while (t /= 10) ++p;
    if (now >= n) {
      tmp = now % (_base / 10);
      __base = 10;
      ans += (tmp * base);
      __base = 10;
      while (tmp /= 10) __base *= 10;
      t = _base / __base;
      while (t /= 10) ++p;
    } else
      ans += (now * base);
    now = 0;
    base *= n;
  }
  cout << ans;
  return 0;
}
