#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
using LL = int64_t;
using pii = pair<int, int>;
const double PI = 2 * asin(1);
LL g_n, g_cnt;
string s;
deque<LL> dll_num;
deque<deque<LL>> ddll_ans;
void pretreat() {}
void input() {
  getchar();
  getline(cin, s);
  dll_num.clear(), ddll_ans.clear();
  for (int i = 0; i < s.size(); ++i) {
    if ('0' <= s[i] && s[i] <= '9') {
      dll_num.push_back(s[i] - '0');
    }
  }
  while (dll_num.front() == 0) {
    dll_num.pop_front();
  }
}
LL get_bit(LL num) {
  LL cnt = 0;
  while (num > 0) {
    ++cnt;
    num /= 10;
  }
  return cnt;
}
LL get_num(deque<LL> dn) {
  LL num = 0;
  for (int i = 0; i < dn.size(); ++i) {
    num = num * 10 + dn[i];
  }
  return num;
}
bool cmp(deque<LL> dn, LL n) {
  while (!dn.empty()) {
    if (dn.front() == 0) {
      dn.pop_front();
    } else {
      break;
    }
  }
  if (dn.size() > g_cnt) {
    return false;
  }
  return get_num(dn) < g_n;
}
void show(deque<LL> dn) {
  for (auto &i : dn) {
    cout << i;
  }
  cout << endl;
}
void solve() {
  if (dll_num.empty()) {
    puts("0");
    return;
  }
  g_cnt = get_bit(g_n);
  int i = dll_num.size() - 1;
  deque<LL> tdll;
  while (i >= 0) {
    tdll.clear();
    int j = i;
    while (j >= 0) {
      tdll.push_front(dll_num[j]);
      if (!cmp(tdll, g_n)) {
        tdll.pop_front();
        break;
      } else {
        --j;
      }
    }
    while (tdll.front() == 0) {
      tdll.pop_front();
      ++j;
    }
    if (!tdll.empty()) {
      ddll_ans.emplace_front(tdll);
    }
    i = j;
    if (i >= 0 && dll_num[i] == 0) {
      tdll.clear();
      int j = i;
      while (j >= 0 && dll_num[j] == 0) {
        tdll.emplace_back(0);
        --j;
      }
      tdll.emplace_front(dll_num[j]);
      if (!cmp(tdll, g_n)) {
        j = i;
        while (!cmp(tdll, g_n)) {
          ddll_ans.emplace_front();
          tdll.pop_back();
          --j;
        }
        i = j;
      }
    }
  }
  LL ans = 0;
  for (int i = 0; i < ddll_ans.size(); ++i) {
    LL num = get_num(ddll_ans[i]);
    ans = ans * g_n + num;
  }
  cout << ans << endl;
}
int main() {
  pretreat();
  while (cin >> g_n) {
    input();
    solve();
  }
  return 0;
}
