#include <bits/stdc++.h>
using namespace std;
char s[70];
int main() {
  long long n;
  cin >> n;
  scanf("%s", s);
  int l = strlen(s);
  long long ans = 0;
  long long p = 1;
  int i = l - 1;
  while (i >= 0) {
    int j = i;
    i--;
    long long c = 0, cc = 0;
    long long ten = 1;
    while (cc < n && j >= 0 && ten < n) {
      cc = c + ten * (s[j] - '0');
      if (cc < n) {
        c = cc;
        if (s[j] != '0') i = j - 1;
      }
      ten *= 10;
      j--;
    }
    ans += p * c;
    p *= n;
  }
  cout << ans << endl;
  return 0;
}
