#include <bits/stdc++.h>
using namespace std;
unsigned long long n, sum, r, dp[100][100], h;
pair<unsigned long long, long long> w[100];
string s;
bool b = 0;
long long fp(long long s, long long f) {
  if (f == 0) return 1;
  if (f == 1) return s;
  unsigned long long x = fp(s, f / 2);
  x *= x;
  if (f % 2 == 1) x *= s;
  return x;
}
int main() {
  memset(dp, -1, sizeof dp);
  cin >> n >> s;
  for (int i = s.size() - 1; i >= 0; i--) {
    r = 1;
    sum = 0;
    b = 0;
    h = 0;
    for (int j = i; j >= 0; j--) {
      if (sum + ((s[j] - '0') * r) >= n) {
        if (i == j) j--;
        if (sum == 0) h = 0;
        w[i].first = sum;
        w[i].second = j + h;
        b = 1;
        break;
      }
      if (s[j] == '0') h++;
      if (s[j] != '0') h = 0;
      sum += (s[j] - '0') * r;
      r *= 10;
    }
    if (sum == 0 && b == 1) w[i].second = i - 1;
    if (sum < n && b == 0) {
      w[i].second = -1;
      w[i].first = sum;
    }
  }
  sum = 0;
  long long po = 0;
  long long pos = s.size() - 1;
  while (pos >= 0) {
    sum += w[pos].first * (fp(n, po));
    po++;
    pos = w[pos].second;
  }
  cout << sum;
  return 0;
}
