#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1e18 + 10;
int n;
string s;
vector<long long> ps;
void min_self(long long &a, long long b) { a = min(a, b); }
vector<vector<long long> > cache;
long long dfs(int digit, int p) {
  if (p == s.size()) {
    return MAX;
  }
  if (digit == 0) {
    int len = s.size() - p;
    if (len > 18 || len == 18 && s[p] > '1' || len > 1 && s[p] == '0') {
      return MAX;
    }
    long long work = stoll(s.substr(p, len));
    return work < n ? work : MAX;
  }
  if (cache[digit][p] >= 0) {
    return cache[digit][p];
  }
  int i = p + 1;
  long long work = s[p] - '0';
  long long ans = MAX;
  while (i <= s.size() && work < n && MAX / ps[digit] >= work) {
    min_self(ans, work * ps[digit] + dfs(digit - 1, i));
    if (work == 0) {
      break;
    }
    work = work * 10 + s[i] - '0';
    i++;
  }
  return cache[digit][p] = ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  cin >> s;
  ps.push_back(1);
  while (MAX / n >= ps.back()) {
    ps.push_back(ps.back() * n);
  }
  cache =
      vector<vector<long long> >(ps.size(), vector<long long>(s.size(), -1));
  long long ans = MAX;
  for (int i = ps.size() - 1; i >= 0; i--) {
    min_self(ans, dfs(i, 0));
  }
  cout << ans << '\n';
}
