#include <bits/stdc++.h>
using namespace std;
const long long linf = (long long)1e18;
const int N = 69;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
const long double eps = 1e-16;
const long double pi = acos(-1.0);
const long double lm = log(linf * 1.0);
long long pw[N];
long long dp[N][N];
string k;
inline void prepare() {}
inline bool leq(const long double &a, const long double &b) {
  return fabs(a - b) < eps || a < b;
}
inline int bound(long long n) {
  long double ln = log(n * 1.0);
  long double s = 0;
  int make_pair = 0;
  while (leq(s + ln, lm)) {
    s += ln, make_pair++;
  }
  return make_pair;
}
inline long long num(int l, int r) {
  --l, --r;
  long long res = 0LL;
  for (int i = r; i >= l; i--) {
    res *= 10LL;
    res += k[i] - '0';
  }
  return res;
}
inline void solve() {
  long long n;
  cin >> n;
  int r = bound(n);
  pw[0] = 1;
  for (int i = 1; i <= r; i++) {
    pw[i] = pw[i - 1] * n;
  }
  cin >> k;
  reverse(k.begin(), k.end());
  int m = ((int)k.size());
  for (int i = 0; i <= m; i++) {
    for (int j = 0; j <= m; j++) {
      dp[i][j] = linf << 1LL;
    }
  }
  for (int i = 1; i <= m; i++) {
    if (i == 1) {
      dp[i][0] = num(1, i);
    } else if (k[i - 1] == '0') {
      continue;
    } else if (num(1, i) < n) {
      dp[i][0] = num(1, i);
    } else {
      break;
    }
  }
  for (int i = 2; i <= m; i++) {
    for (int j = 1; j <= min(r, i); j++) {
      if (k[i - 1] == '0') {
        dp[i][j] = dp[i - 1][j - 1];
      } else {
        for (int p = i; p >= j; p--) {
          if (num(p, i) < n && leq(log(pw[j]) + log(num(p, i)), lm)) {
            dp[i][j] = min(dp[i][j], dp[p - 1][j - 1] + pw[j] * num(p, i));
          }
        }
      }
    }
  }
  long long ans = linf << 1LL;
  for (int j = 0; j <= min(r, m); j++) {
    ans = min(ans, dp[m][j]);
  }
  cout << ans;
}
int main() {
  int tests = 1;
  prepare();
  while (tests--) {
    solve();
  }
}
