#include <bits/stdc++.h>
using namespace std;
int n;
char s[65];
unsigned long long t, sum, p, last, _mi[65];
int main() {
  scanf("%d", &n);
  scanf("%s", s + 1);
  int len = strlen(s + 1);
  int mi = 0, tot = 0;
  _mi[0] = 1;
  last = len;
  p = 1;
  for (int i = 1; i <= 61; i++) _mi[i] = _mi[i - 1] * n;
  for (int i = len; i >= 1; i--) {
    if (t + p * (s[i] - '0') < n) {
      t += p * (s[i] - '0');
      p *= 10;
    } else {
      sum += t * _mi[mi];
      int j = i + 1;
      while (s[j] == '0' && j <= last) j++;
      if (j == last + 1) j--;
      i = j - 1;
      last = i;
      mi++;
      t = s[i] - '0';
      p = 10;
    }
  }
  sum = sum + t * _mi[mi];
  cout << sum << endl;
  return 0;
}
