#include <bits/stdc++.h>
using namespace std;
const int z = (int)1e5 + 111;
const int INF = (int)1e9 * 2 + 111;
long long step(int n, int x) {
  long long ans = 1;
  for (int i = 1; i <= x; i++) ans *= n;
  return ans;
}
int main() {
  stringstream sstr;
  long long ans = 0;
  int n, s = 1, kol = 0;
  long long p;
  string k;
  cin >> n >> k;
  while (k.length()) {
    string st = "";
    do {
      st = k.back() + st;
      k.erase(k.length() - 1, 1);
      sstr.clear();
      sstr << st;
      sstr >> p;
      if (p >= n) {
        k += st[0];
        st.erase(0, 1);
        while (st[0] == '0' && st.length() > 1) {
          k += st[0];
          st.erase(0, 1);
        }
        sstr.clear();
        sstr << st;
        sstr >> p;
        break;
      }
    } while (k.length());
    ans += p * step(n, kol);
    kol++;
  }
  cout << ans;
  return 0;
}
