#include <bits/stdc++.h>
using namespace std;
long long fastExp(long long base, long long p) {
  if (p == 0)
    return 1;
  else if (p == 1)
    return base;
  else {
    long long res = fastExp(base, p / 2);
    res *= res;
    if (p % 2 == 1) res *= base;
    return res;
  }
}
int n;
string s;
long long memo[80][80];
long long solve(int idx, int p) {
  if (idx == -1) return 0;
  if (memo[idx][p] != -1) return memo[idx][p];
  long long INF = fastExp(10, 18);
  long long ans = INF;
  for (int i = idx; i >= 0; i--) {
    string sub = s.substr(i, idx - i + 1);
    long long subNum = 0;
    for (int j = idx, h = 0; subNum < n && j >= i; j--, h++) {
      long long temp = subNum;
      subNum += (s[j] - '0') * fastExp(10, h);
      if (subNum - temp != (s[j] - '0') * fastExp(10, h)) {
        subNum = n;
        break;
      }
    }
    if (subNum >= n || (sub[0] == '0' && sub.size() > 1)) continue;
    long long aux = subNum * fastExp(n, p);
    if (aux / fastExp(n, p) != subNum || aux < 0) continue;
    long long temp = aux;
    aux += solve(i - 1, p + 1);
    if (aux - temp != solve(i - 1, p + 1) || aux < 0) continue;
    ans = min(ans, aux);
  }
  return memo[idx][p] = ans;
}
int main() {
  cin >> n >> s;
  memset(memo, -1, sizeof memo);
  cout << solve(s.size() - 1, 0) << endl;
  ;
  return 0;
}
