#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
char str[maxn];
long long pow(long long n, long long k) {
  long long ans = 1;
  while (k > 0) {
    if (k & 1) ans *= n;
    k >>= 1;
    n = n * n;
  }
  return ans;
}
int main() {
  long long n, ans = 0;
  cin >> n;
  cin >> (str + 1);
  int len = strlen(str + 1);
  long long k = 0;
  str[0] = '0';
  int pre = len;
  for (int i = len; i >= 0; i--) {
    int pos = i;
    long long num = 0;
    while (pos <= pre && num < n) {
      num *= 10;
      num += str[pos] - '0';
      pos++;
    }
    if (num >= n || i == 0) {
      pos = i + 1;
      num = 0;
      int flag = 0;
      while (str[pos] == '0') {
        pos++;
        flag = 1;
      }
      int temp = pos - 1;
      while (pos <= pre) {
        num *= 10;
        num += str[pos] - '0';
        pos++;
      }
      if (num == 0 && str[pre] == '0') {
        str[pre] = '\0';
        k++;
        i++;
        pre--;
        continue;
      }
      if (flag) i++;
      ans += num * pow(n, k);
      k++;
      pre = temp;
    }
  }
  cout << ans << endl;
  return 0;
}
