#include <bits/stdc++.h>
using namespace std;
long long n;
long long F[66], dp[66][66];
string s;
int m;
bool ok = 0;
long long good(long long x, long long y) {
  if (ok) return 0;
  if (y == 0) return 0;
  if (y == 1) return x;
  long long t = good(x, y / 2);
  if (t > 1000000000000000000) {
    ok = 1;
    return 0;
  }
  if (y & 1)
    return t + t + x;
  else
    return t + t;
}
void tap(int h) {
  if (s[h] == '0') {
    for (int j = 1; j <= 60; j++) dp[h][j] = dp[h - 1][j - 1];
    return;
  }
  long long x = 0;
  for (int i = h; i > 0; i--) {
    x = x * 10LL + (s[i] - '0');
    if (x < n) {
      for (int j = 0; j <= 60; j++) {
        if (dp[i - 1][j] == 1000000000000000007 || F[j + 1] == 0) continue;
        ok = 0;
        good(x, F[j + 1]);
        if (ok == 0 && dp[i - 1][j] + x * F[j + 1] < 1000000000000000007)
          dp[h][j + 1] = min(dp[h][j + 1], dp[i - 1][j] + x * F[j + 1]);
      }
    } else
      break;
  }
}
int main() {
  cin >> n >> s;
  reverse(s.begin(), s.end());
  int g = 60;
  F[0] = 1;
  for (int i = 1; i <= 60; i++) {
    F[i] = F[i - 1] * n;
    ok = 0;
    good(F[i - 1], n);
    if (ok) {
      F[i] = 0;
      g = i - 1;
      break;
    }
  }
  for (int i = 0; i <= 60; i++)
    for (int h = 0; h <= 60; h++) dp[i][h] = 1000000000000000007;
  m = s.length();
  for (int i = 0; i <= m - 1; i++) {
    int j = i;
    long long x = 0;
    if (s[i] == '0' && i == 0) {
      dp[i][0] = 0;
      continue;
    }
    if (s[i] == '0') continue;
    while (j >= 0 && x < n) x = x * 10LL + (s[j] - '0'), j--;
    if (j == -1 && x < n) dp[i][0] = x;
  }
  for (int i = 1; i <= m - 1; i++) tap(i);
  long long ans = 1000000000000000007;
  for (int i = 0; i <= 60; i++) ans = min(ans, dp[m - 1][i]);
  cout << ans;
}
