#include <bits/stdc++.h>
using namespace std;
string s;
int n;
long long jiechen(int n, int m) {
  return m == 0 ? 1 : 1LL * n * jiechen(n, m - 1);
}
int judge(int num, int len, int bit) {
  int r = num;
  long long g = 0;
  for (int i = num; i < len && i < num + bit; i++) {
    g = g + jiechen(10, i - num) * 1LL * (s[i] - '0');
    if (g >= n) break;
    if (s[i] != '0' && g < n) {
      r = i;
    }
  }
  return r;
}
int main() {
  cin >> n >> s;
  int len = s.size();
  for (int i = 0; i < len / 2; i++) {
    swap(s[i], s[len - i - 1]);
  }
  int l = 0, k = 0, bit = 0, m = n;
  long long ans = 0;
  while (m > 0) {
    bit++;
    m = m / 10;
  }
  while (l < len) {
    int r = judge(l, len, bit);
    int sum = 0;
    for (int i = l; i <= r; i++) {
      sum = sum + jiechen(10, i - l) * (s[i] - '0');
    }
    ans = ans + 1LL * jiechen(n, k) * sum;
    k++;
    l = r + 1;
  }
  cout << ans << endl;
}
