#include <bits/stdc++.h>
const double eps = 0.000000001;
using namespace std;
int beg;
long long p(long long x) {
  long long ret = 1;
  if (x >= 18) {
    return 1e18;
  }
  for (int i = 0; i < x; i++) {
    ret *= 10;
  }
  return ret;
}
int main() {
  long long deg = 1;
  long long pow = 0;
  long long cnt = 0;
  long long ans = 0;
  long long n;
  char data[105];
  cin >> n >> data;
  beg = strlen(data) - 1;
  while (beg >= 0) {
    if (cnt + (p(pow) * (data[beg] - '0')) >= n) {
      while (data[beg + 1] - '0' == 0 && pow != 1) {
        pow--;
        beg++;
      }
      pow = 1;
      ans += cnt * deg;
      deg *= n;
      cnt = data[beg] - '0';
    } else {
      cnt += (p(pow) * (data[beg] - '0'));
      pow++;
    }
    beg--;
  }
  ans += cnt * deg;
  cout << ans << "\n";
  cin >> n;
  return 0;
}
