#include <bits/stdc++.h>
using namespace std;
int n, len;
char s[100];
long long convert() {
  long long ret = 0;
  for (int i = 1; i <= len; ++i) {
    ret = ret * n + s[i] - '0';
  }
  return ret;
}
long long f[65];
long long cut(int l, int r) {
  l++;
  if (l != r && s[l] == '0') return n;
  long long ret = 0;
  for (int i = l; i <= r; i++) {
    ret = ret * 10 + s[i] - '0';
    if (ret >= n) return ret;
  }
  return ret;
}
int main() {
  scanf("%d", &n);
  scanf("%s", s + 1);
  len = strlen(s + 1);
  if (n <= 10)
    cout << convert() << endl;
  else if (s[1] == '0')
    puts("0");
  else {
    memset(f, 0x3f, sizeof f);
    f[0] = 0;
    for (int i = 1; i <= len; ++i) {
      for (int j = i - 1; j > -1; j--) {
        long long part = cut(j, i);
        if (part >= n) continue;
        if ((long double)(f[j]) * (long double)(n) > (long double)(f[64]))
          continue;
        f[i] = min(f[i], f[j] * n + part);
      }
    }
    printf("%I64d\n", f[len]);
  }
  return 0;
}
