#include <bits/stdc++.h>
using namespace std;
int main() {
  int base;
  string n;
  scanf("%d\n", &base);
  getline(cin, n);
  string ret;
  int sz = n.size();
  int curr = sz - 1;
  long long mult = 1;
  long long ans = 0;
  while (curr >= 0) {
    long long tmp = 0;
    long long pow = 1;
    int pow_id = 0;
    int prev = curr;
    while (pow_id <= 9 && tmp + pow * (n[curr] - '0') < base) {
      tmp += pow * (n[curr] - '0');
      pow *= 10;
      pow_id++;
      curr--;
      if (curr == -1) break;
    }
    ans += (tmp * mult);
    mult *= base;
    if (curr == -1) break;
    if (n[curr + 1] == '0') {
      while (curr + 1 < prev && n[curr + 1] == '0') curr++;
    }
    if (curr == prev) curr--;
  }
  cout << ans << "\n";
}
