#include <bits/stdc++.h>
using namespace std;
int main() {
  string k;
  string nt;
  long long n, x = 0, temp, power = 1;
  cin >> nt >> k;
  int dc = nt.length();
  n = strtoll(nt.c_str(), NULL, 10);
  int i = k.length() - dc, tdc;
  for (; i > -1; i -= dc) {
    tdc = dc;
    while (k[i] == '0' && tdc > 0) {
      i++;
      tdc--;
    }
    if (tdc == 0) {
      power *= n;
      i--;
      continue;
    }
    temp = strtoll(k.substr(i, tdc).c_str(), NULL, 10);
    if (temp >= n) {
      i++;
      tdc = dc - 1;
      while (k[i] == '0' && tdc > 0) {
        i++;
        tdc--;
      }
      if (tdc == 0) {
        i--;
        power *= n;
        continue;
      }
      temp = strtoll(k.substr(i, tdc).c_str(), NULL, 10);
    }
    x += temp * power;
    power *= n;
  }
  temp = strtoll(k.substr(0, i + dc).c_str(), NULL, 10);
  x += temp * power;
  cout << x << endl;
  return 0;
}
