#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  unsigned long long n;
  cin >> n;
  string k;
  cin >> k;
  reverse(k.begin(), k.end());
  unsigned long long len = k.size();
  unsigned long long power[len + 2];
  power[0] = 1;
  for (unsigned long long i = 1; i <= len + 1; i++) power[i] = power[i - 1] * n;
  unsigned long long g = 0;
  unsigned long long ans = 0;
  for (unsigned long long i = 0; i < len;) {
    unsigned long long sum = 0;
    unsigned long long help = 1;
    unsigned long long p = i;
    while (sum + (k[p] - '0') * help < n && p < len) {
      sum += (k[p] - '0') * help;
      help *= 10;
      p++;
    }
    if (sum == 0) {
      i++;
      g++;
    } else {
      for (int j = p - 1; j >= i && k[j] == '0'; j--) p--;
      i = p;
      ans += sum * power[g++];
    }
  }
  cout << ans << endl;
  return 0;
}
