#include <bits/stdc++.h>
using namespace std;
void read_file(bool outToFile = true) {}
const int MAXN = 60 + 1 + 9;
int A[MAXN];
char str[MAXN];
int n;
long long base;
int main() {
  read_file();
  while (scanf("%lld", &base) != -1) {
    scanf("%s", str);
    n = strlen(str);
    for (int i = 0; i < n; i++) {
      A[i] = str[i] - '0';
    }
    long long ans = 0;
    long long pbase = 1;
    for (int i = n - 1; true;) {
      int sj = i;
      long long x = A[i];
      long long po = 10;
      int j = i - 1;
      while (true) {
        if (j == -1) break;
        long long nx = po * A[j] + x;
        if (nx >= base) break;
        if (po >= base) break;
        po *= 10;
        if (A[j] != 0) sj = j;
        x = nx;
        j--;
      }
      ans += x * pbase;
      i = sj - 1;
      if (i == -1) break;
      pbase *= base;
    }
    printf("%lld\n", ans);
  }
}
