#include <bits/stdc++.h>
using namespace std;
int n;
string S;
long long dp[222][222];
long long GetAnswer(int pos, int numdigs) {
  if (pos == S.size()) {
    if (numdigs == 0)
      return 0;
    else
      return -1;
  }
  if (numdigs == 0) return -1;
  if (dp[pos][numdigs] != -2) return dp[pos][numdigs];
  long long ret = -1;
  long long x = 0;
  if ((numdigs - 1.0) * log(n) > log(1400000000000000000ll))
    return dp[pos][numdigs] = -1;
  long long npow = 1;
  for (int j = 0; j < numdigs - 1; j++) npow *= n;
  if (npow > 1000000000000000000ll) return dp[pos][numdigs] = -1;
  for (int j = pos; j < S.size(); j++) {
    if (S[pos] == '0' && j > pos) break;
    x = x * 10 + S[j] - '0';
    if (x >= n) break;
    long long curr = GetAnswer(j + 1, numdigs - 1);
    if (curr == -1 || curr > 1000000000000000000ll ||
        x > 1000000000000000000ll / npow)
      continue;
    if (log(x) + (numdigs - 1.0) * log(n) > log(1400000000000000000ll - curr))
      continue;
    curr += x * npow;
    if (curr <= 1000000000000000000ll && (ret == -1 || curr < ret)) ret = curr;
  }
  return dp[pos][numdigs] = ret;
}
int main() {
  cin >> n >> S;
  long long answer = -1;
  for (int j = 0; j < 222; j++)
    for (int k = 0; k < 222; k++) dp[j][k] = -2;
  for (int numdigs = 1; numdigs <= 61; numdigs++) {
    long long curr = GetAnswer(0, numdigs);
    if (curr == -1) continue;
    if (answer == -1 || (curr < answer)) answer = curr;
  }
  cout << answer << endl;
}
