#include <bits/stdc++.h>
using namespace std;
unsigned long long toint(string s) {
  stringstream ss(s);
  unsigned long long res;
  ss >> res;
  return res;
}
unsigned long long pot(unsigned long long x, int ex) {
  unsigned long long res = 1;
  for (int i = 0; i < ex; ++i) {
    res *= x;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  string n, k;
  cin >> n >> k;
  unsigned long long nro = toint(n);
  int l = k.length();
  int nl = n.length();
  int e = l - 1;
  int el = 0;
  unsigned long long res = 0;
  for (int i = l - 1; i >= 0; i--) {
    int sz = 1;
    string pk = k.substr(e - sz + 1, sz);
    while ((pk.length() < nl) || (pk.length() == nl && pk < n)) {
      sz++;
      if (e - sz + 1 < 0) break;
      pk = k.substr(e - sz + 1, sz);
    }
    sz--;
    pk = k.substr(e - sz + 1, sz);
    int j = 0;
    while (j < pk.length() && pk[j] == '0') j++, sz--;
    if (j == pk.length()) j--, sz++;
    pk = k.substr(e - sz + 1, sz);
    res += toint(pk) * pot(nro, el);
    el++;
    e = e - sz;
    i = e + 1;
  }
  cout << res << "\n";
  return 0;
}
