#include <bits/stdc++.h>
using namespace std;
inline int ra() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long n, m = 1, ans;
string s;
long long get(int l, int r) {
  long long sum = 0;
  for (int i = l; i <= r; i++) {
    sum = sum * 10 + s[i] - '0';
    if (sum > n) break;
  }
  return sum;
}
int main() {
  n = (long long)ra();
  cin >> s;
  int len = s.length();
  int last = len - 1, i = len - 1;
  while (i != -1) {
    if (s[i] != '0' && get(i, last) < n) {
      i--;
      if (i == -1) {
        ans += m * get(0, last);
        break;
      }
      continue;
    }
    if (s[i] == '0') {
      int j = i;
      while (j != -1 && get(j, last) < n && s[j] == '0') j--;
      while (s[last] == '0' && get(j, last) >= n) m = m * n, last--;
      if (s[j] != '0' && get(j, last) < n) i = j;
      if (s[j] != '0' && get(j, last) >= n) {
        ans += m * get(i, last);
        last = i;
        m = m * n;
      }
    }
    if (s[i] != '0' && get(i, last) >= n) {
      ans += m * get(i + 1, last);
      last = i;
      m *= n;
    }
  }
  cout << ans;
  return 0;
}
