#include <bits/stdc++.h>
using namespace std;
long long int M = LLONG_MAX;
int check_overflow(long long int a, long long int b) {
  if (a != 0 && b != 0 && (a > M / b || b > M / a)) return 1;
  return 0;
}
long long int pow_10[19];
int main() {
  pow_10[0] = 1;
  for (int i = 1; i <= 18; i++) pow_10[i] = pow_10[i - 1] * 10;
  long long int n;
  string k;
  cin >> n >> k;
  long long int l = k.length();
  long long int arr[l + 1];
  for (long long int i = 1; i <= l; i++) arr[i] = k[i - 1] - '0';
  long long int dp[l + 1];
  for (long long int i = 1; i <= l; i++) dp[i] = LLONG_MAX;
  dp[1] = arr[1];
  dp[0] = 0;
  for (long long int i = 2; i <= l; i++) {
    long long int pwr = 0;
    long long int v = 0;
    for (long long int j = i; j > 0; j--) {
      v += pow_10[pwr] * arr[j];
      pwr++;
      if (pwr > 18) break;
      if (arr[j] == 0 && pwr > 1) continue;
      if (v >= n) break;
      if (check_overflow(n, dp[j - 1]) == 0)
        dp[i] = min(dp[i], v + n * (dp[j - 1]));
    }
  }
  cout << dp[l] << endl;
  return 0;
}
