#include <bits/stdc++.h>
using namespace std;
const int N = 105 + 5;
long long n;
char s[N];
bool b[N];
int main() {
  scanf("%d", &n);
  scanf("%s", s + 1);
  int len = strlen(s + 1);
  long long base = 1;
  int i = len;
  long long ans = 0;
  while (i >= 1) {
    long long sum = 0, t = 1;
    int x = i;
    while (sum + max(1, (s[i] - '0')) * t < n && i >= 1) {
      sum += (s[i] - '0') * t;
      t *= 10;
      i--;
    }
    ans += sum * base;
    base *= n;
    while (s[i + 1] == '0' && i < x - 1) i++;
  }
  printf("%lld", ans);
  return 0;
}
