#include <bits/stdc++.h>
using namespace std;
long long pow(long long x, int n) {
  long long ret = 1;
  while (n) {
    if (n % 2) ret *= x;
    x *= x;
    n /= 2;
  }
  return ret;
}
int main(void) {
  int i, n;
  string k;
  cin >> n >> k;
  int num = 0;
  long long ans = 0;
  int zero = 0, d = 0, dd = 0;
  for (i = (int)(k.size()) - 1; i >= 0; i--) {
    long long nnum = num + pow(10, d++) * (k[i] - '0');
    if (nnum >= n) {
      if (num == 0)
        zero--;
      else
        ans = ans + num * pow(n, dd);
      num = k[i] - '0';
      d = 1;
      while (zero && num * 10LL < n) {
        num *= 10;
        d++;
        zero--;
      }
      dd += zero + 1;
      zero = 0;
    } else if (d > 10) {
      zero++;
      if (num == 0) {
        zero--;
      } else {
        ans = ans + num * pow(n, dd);
      }
      dd++;
      num = 0;
      d = zero;
    } else {
      num = nnum;
      if (k[i] == '0')
        zero++;
      else
        zero = 0;
    }
  }
  ans = ans + num * pow(n, dd);
  cout << ans << endl;
  return 0;
}
