#include <bits/stdc++.h>
using namespace std;
string k;
long long n;
long long Judge(int L, int R) {
  int flag = 0;
  for (int i = L; i <= R; i++) {
    if (k[i] != '0') flag = 1;
  }
  if (flag == 1 && k[L] == '0') return -1;
  long long ans = 0;
  for (int i = L; i <= R; i++) {
    ans = (ans * 10 + (k[i] - '0'));
  }
  if (ans >= n) {
    return -1;
  } else
    return ans;
}
int getL(int l, int r) {
  for (int i = l; i <= r; i++) {
    if (k[i] != '0') return i;
  }
  return r;
}
int main() {
  cin >> n >> k;
  long long ans = 0;
  int len = k.size();
  long long base = 1;
  int l = len - 1;
  int r = len - 1;
  long long val;
  while (r >= 0) {
    for (int i = 0; i <= r; i++) {
      if (r - i > 17) continue;
      val = 0;
      for (int j = i; j <= r; j++) val = val * 10 + k[j] - '0';
      if (val < n) {
        l = i;
        break;
      }
    }
    while (l < r && k[l] == '0') l++;
    ans = ans + base * val;
    base *= n;
    r = l - 1;
  }
  cout << ans << endl;
  return 0;
}
