#include <bits/stdc++.h>
using namespace std;
long long N;
string S;
long long sol;
long long dim;
long long e;
long long last() {
  long long d = 1ll;
  long long n = 0ll;
  long long sz = (long long)(S.size());
  int zero = 0;
  for (long long i = sz - 1; i >= sz - dim && i >= 0 && n < N; i--) {
    if (d * (long long)(S[i] - '0') + n < N) {
      if (S[i] == '0')
        zero++;
      else
        zero = 0;
      n += d * (long long)(S[i] - '0'), d *= 10ll, S.pop_back();
    }
  }
  if (n == 0) zero--;
  while (zero > 0) S.push_back('0'), zero--;
  return n;
}
int main() {
  cin >> N >> S;
  long long c = N;
  while (c) c /= 10, dim++;
  e = 1ll;
  while (!S.empty()) {
    sol += e * last();
    e *= N;
  }
  cout << sol;
  return 0;
}
