#include <bits/stdc++.h>
using namespace std;
const int maxlen = 81;
char s[maxlen];
int base;
long long int greedy(int r) {
  if (!r) return 0;
  int l = r;
  long long val = 0, t = 1;
  for (int i = r; i >= 1 && t < base; --i, t *= 10)
    if (val + (s[i] - '0') * t < base) {
      val += (s[i] - '0') * t;
      if (s[i] != '0') l = i;
    } else
      break;
  return greedy(l - 1) * base + val;
}
int main() {
  scanf("%d%s", &base, s + 1);
  cout << greedy(strlen(s + 1)) << endl;
  return 0;
}
