#include <bits/stdc++.h>
using namespace std;
long long n, k, p;
string s;
vector<long long> mem;
long long solve(int i) {
  if (mem[i] != -1) return mem[i];
  if (i == 0) return 0;
  long long tmp = stoll(s.substr(i - 1, 1));
  long long res = 1ll << 62;
  for (int j = i - 1; tmp < n; --j) {
    if (s[j] != '0' || j == i - 1) {
      long long tmptmp = solve(j);
      if (tmptmp < ((1ll << 62) - tmp) / n && tmptmp > -1)
        res = min(res, tmp + n * tmptmp);
    }
    if (j - 1 < 0) break;
    tmp = stoll(s.substr(j - 1, i - j + 1));
  }
  mem[i] = res;
  return res;
}
int main(int argc, char const *argv[]) {
  cin >> n;
  cin >> s;
  k = s.length();
  if (n < 11) {
    long long res = 0;
    for (int i = 0; i < k; ++i) {
      res *= n;
      res += stoi(s.substr(i, 1));
    }
    cout << res << endl;
    return 0;
  }
  mem = vector<long long>(k + 1, -1);
  cout << solve(k) << endl;
  return 0;
}
