#include <bits/stdc++.h>
using namespace std;
int main() {
  string k, te;
  char ch;
  long long int n, si, last, cnt, tmp, x, ini, j, i, cur, fact, fc, rem, quo,
      ans, temp, val, z;
  ans = 0LL;
  cin >> n;
  cin >> k;
  si = k.size();
  last = si - 1;
  cnt = 0;
  tmp = n;
  te = "";
  while (tmp) {
    cnt++;
    x = tmp % 10;
    tmp /= 10;
    ch = (char)(x + 48);
    te = ch + te;
  }
  fact = 1LL;
  while (last >= 0) {
    ini = last - cnt + 1;
    j = 0;
    if (ini < 0) {
      cur = 0;
      ini = 0;
    } else {
      if (k[ini] < te[j]) {
        cur = ini;
      } else {
        if (k[ini] > te[j]) {
          cur = ini + 1;
        } else {
          z = ini;
          while (z < last && k[z] == te[j]) {
            z++;
            j++;
          }
          if (k[z] < te[j]) {
            cur = ini;
          } else {
            cur = ini + 1;
          }
        }
      }
    }
    while (cur < last && k[cur] == '0') {
      cur++;
    }
    rem = 0LL;
    temp = 0LL;
    fc = 1LL;
    for (i = last; i >= cur; i--) {
      x = (k[i] - 48);
      val = x * fact;
      val = val + rem;
      rem = val / 10;
      quo = val % 10;
      temp = quo * fc + temp;
      fc = fc * 10LL;
    }
    while (rem) {
      quo = rem % 10;
      temp = quo * fc + temp;
      rem = rem / 10;
      fc = fc * 10LL;
    }
    last = cur - 1;
    if (last >= 0) {
      fact = fact * n;
    }
    ans = ans + temp;
  }
  cout << ans << endl;
  return 0;
}
