#include <bits/stdc++.h>
using namespace std;
long long dp[65][65];
long long n;
long long a[65], l;
long long pow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b % 2 == 1) res = res * a;
    b /= 2;
    a = a * a;
  }
  return res;
}
long long func(long long pos, long long cut) {
  if (pos == l) return 0;
  if (dp[pos][cut] != -1) return dp[pos][cut];
  long long ans = 2000000000000000005;
  long long x = 0;
  for (int i = pos; i < l; i++) {
    if (a[i] == 0) {
      if (i != pos)
        continue;
      else
        ans = min(ans, func(i + 1, cut + 1));
    }
    long long z;
    if (pow(10ll, i - pos) >= 0 && pow(10ll, i - pos) * a[i] >= 0 &&
        pow(10ll, i - pos) * a[i] + x >= 0)
      z = pow(10ll, i - pos) * a[i] + x;
    else
      break;
    if (z >= n) break;
    if (pow(n, cut) >= 0 && pow(n, cut) * z >= 0 &&
        pow(n, cut) * z + func(i + 1, cut + 1) >= 0)
      ans = min(ans, pow(n, cut) * z + func(i + 1, cut + 1));
    x = z;
  }
  return dp[pos][cut] = ans;
}
int main() {
  memset(dp, -1, sizeof(dp));
  scanf("%lld", &n);
  string s;
  cin >> s;
  l = 0;
  memset(a, 0, sizeof(0));
  int m = s.length();
  for (int i = m - 1; i >= 0; i--) {
    a[l++] = s[i] - '0';
  }
  long long ans = func(0, 0);
  cout << ans << endl;
  return 0;
}
