#include <bits/stdc++.h>
using namespace std;
long long n, len;
char s[100];
const long long Inf = 1e18;
long long dp[100];
signed main() {
  cin >> n;
  scanf("%s", s + 1);
  len = strlen(s + 1);
  for (long long i = 1; i <= len; i++) dp[i] = Inf;
  dp[0] = 0;
  for (long long i = 1; i <= len; i++) {
    if (s[i] == '0') {
      dp[i] = min(dp[i], n * dp[i - 1]);
      continue;
    }
    long long cur = 0;
    for (long long j = i; j <= len; j++) {
      cur = cur * 10 + s[j] - '0';
      if (cur >= n) break;
      if ((Inf - cur) / n >= dp[i - 1]) dp[j] = min(dp[j], dp[i - 1] * n + cur);
    }
  }
  cout << dp[len] << endl;
  return 0;
}
