#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  long long i, n, ans = 0;
  string s;
  cin >> n >> s;
  long long len = s.length() - 1, pro = 1;
  for (i = len; i >= 0; i--) {
    long long x = 0, k, j = i, temp = 1, loc = i;
    while (j >= 0 && temp < n) {
      k = x;
      k += (int)(s[j] - '0') * temp;
      if (k >= n) break;
      if (s[j] != '0') loc = j;
      x = k;
      j--;
      temp *= 10;
    }
    ans += pro * x;
    pro *= n;
    i = loc;
  }
  cout << ans;
  return 0;
}
