#include <bits/stdc++.h>
using namespace std;
int n, len;
string s;
int a[100];
int main() {
  cin >> n >> s;
  len = int(s.size());
  for (int i = 0; i < (int)(len); ++i) {
    a[i] = int(s[i] - '0');
  }
  long long ans = 0;
  long long mul = 1;
  while (len) {
    int best = -1;
    for (int i = 0; i < (int)(len); ++i)
      if (a[i] != 0) {
        long long cur = 0;
        for (int j = i; j < len; ++j) {
          cur = 10 * cur + a[j];
          if (cur >= n) {
            break;
          }
        }
        if (cur < n) {
          best = i;
          break;
        }
      }
    if (best == -1) {
      best = len - 1;
    }
    long long cur = 0;
    for (int j = best; j < len; ++j) {
      cur = 10 * cur + a[j];
    }
    ans += mul * cur;
    mul *= n;
    len = best;
  }
  cout << ans << endl;
  return 0;
}
