#include <bits/stdc++.h>
using namespace std;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const long long LINF = 1000000000000000000;
const long long MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline void add(T& a, T b) {
  a = ((a + b) % MOD + MOD) % MOD;
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n;
  string S;
  cin >> n >> S;
  reverse(S.begin(), S.end());
  long long cur = 0;
  long long base = 1;
  long long ans = 0;
  int digits = 0;
  long long tmp = n;
  while (tmp > 0) {
    tmp /= 10;
    digits++;
  }
  while (cur < (int)S.size()) {
    int ok = cur;
    long long tmp = 0;
    for (long long i = cur; i < (int)S.size(); i++) {
      if (S[i] == '0') continue;
      tmp = tmp + (S[i] - '0') * powl(10LL, i - cur);
      if (i - cur > digits) break;
      if (tmp < n)
        ok = i;
      else
        break;
    }
    tmp = 0;
    for (long long i = cur; i <= ok; i++) {
      tmp = tmp + (S[i] - '0') * powl(10LL, i - cur);
    }
    ans += base * tmp;
    base *= n;
    cur = ok + 1;
  }
  cout << ans << endl;
}
