#include <bits/stdc++.h>
using namespace std;
const long long N = 65;
long long dp[N];
long long n;
string k;
long long fnc(long long i) {
  if (i < 0)
    return 0;
  else if (dp[i] != -1)
    return dp[i];
  long long &ans = dp[i];
  ans = ((long long)1e18 + 1);
  long long c = 0;
  long long p = 1;
  for (__typeof((i)) j = (i); j >= (0); j--) {
    if (k[j] - '0' <= (((long long)1e18 + 1) - 1 - c) / p)
      c = c + p * (k[j] - '0');
    else
      c = ((long long)1e18 + 1);
    if (p <= (((long long)1e18 + 1) - 1 / 10))
      p = p * 10;
    else
      p = ((long long)1e18 + 1);
    if (k[j] == '0') {
      if (j == i and fnc(j - 1) <= (((long long)1e18 + 1) - 1) / n)
        ans = min(ans, n * fnc(j - 1));
    } else if (c < n) {
      if (fnc(j - 1) <= (((long long)1e18 + 1) - 1 - c) / n)
        ans = min(ans, c + n * fnc(j - 1));
    } else
      break;
  }
  return ans;
}
void solve() {
  cin >> n >> k;
  memset(dp, -1, sizeof(dp));
  long long ans = fnc((long long)k.size() - 1);
  cout << ans << '\n';
}
signed main() {
  long long t;
  ios_base::sync_with_stdio(false);
  t = 1;
  while (t--) solve();
  return 0;
}
