#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
const int maxn = 100005;
inline int getint() {
  int r = 0;
  bool b = true;
  char c = getchar();
  while ('0' > c || c > '9') {
    if (c == '-') b = false;
    c = getchar();
  }
  while ('0' <= c && c <= '9') {
    r = r * 10 + (c - '0');
    c = getchar();
  }
  if (b) return r;
  return -r;
}
char str[maxn];
long long n, ne;
bool check(int l, int r) {
  if (str[l] == '0' && r > l) return false;
  if (str[l] == '0' && l == r) return true;
  if (r - l > 10) return false;
  long long ret = 0;
  for (int i = l; i <= r; ++i) ret = ret * 10 + str[i] - '0';
  if (ret >= n) return false;
  return true;
}
long long getnum(int l, int r) {
  long long ret = 0;
  for (int i = l; i <= r; ++i) ret = ret * 10 + str[i] - '0';
  return ret;
}
int main() {
  n = getint();
  scanf("%s", str + 1);
  int len = strlen(str + 1);
  int ptr = len;
  long long T = 1ll;
  long long ans = 0;
  while (ptr >= 1) {
    for (int i = 1; i <= ptr; ++i)
      if (check(i, ptr)) {
        ans += T * getnum(i, ptr);
        T *= n;
        ptr = i - 1;
        break;
      }
  }
  cout << ans;
}
