#include <bits/stdc++.h>
using namespace std;
string k, n;
bool sat(string s) {
  if (s.length() > n.length()) return true;
  if (s.length() == n.length()) {
    return s >= n;
  }
  return false;
}
int main() {
  cin >> n;
  long long x = 1;
  long long nn = stoll(n);
  cin >> k;
  string curr = "";
  long long ans = 0;
  int i = k.length() - 1;
  while (i >= 0) {
    curr = k[i] + curr;
    if (sat(curr)) {
      curr.erase(0, 1);
      int z = curr.find_first_not_of('0');
      if (z != -1)
        curr.erase(0, z);
      else
        z = curr.length() - 1;
      ans += curr[0] == '0' ? 0 : stoll(curr) * x;
      curr = "";
      x *= nn;
      i += z;
    } else {
      --i;
    }
  }
  ans += stoll(curr) * x;
  cout << ans << endl;
  return 0;
}
