#include <bits/stdc++.h>
using namespace std;
bool corrent_mult(long long a, long long b) {
  long long a1 = a / 1000000000;
  long long a2 = a % 1000000000;
  long long b1 = b / 1000000000;
  long long b2 = b % 1000000000;
  long long c1 = a1 * b1;
  long long c2 = a1 * b2 + a2 * b1;
  long long c3 = a2 * b2;
  c2 += c3 / 1000000000;
  c3 = c3 % 1000000000;
  c1 += c2 / 1000000000;
  c2 = c2 % 1000000000;
  return c1 < 2;
}
int main() {
  ios_base::sync_with_stdio(false);
  long long n;
  cin >> n;
  string number;
  cin >> number;
  vector<long long> dp;
  dp.resize(number.size() + 1, LLONG_MAX);
  dp[0] = 0;
  for (int i = 1; i < dp.size(); i++)
    for (int j = 1; j <= 9; j++)
      if ((i - j >= 0 && number[i - j] != '0') ||
          (j == 1 && number[i - j] == '0')) {
        long long current = 0;
        for (int k = i - j; k < i; k++) {
          current *= 10;
          current += number[k] - '0';
        }
        if (corrent_mult(dp[i - j], n))
          if (current < n) dp[i] = min(dp[i], current + dp[i - j] * n);
      }
  cout << dp[number.size()] << endl;
  return 0;
}
