#include <bits/stdc++.h>
using namespace std;
const long long inf = (1LL << 62) - 1;
char sz[110];
long long dp[110], n;
int len;
int main() {
  scanf("%lld", &n);
  scanf("%s", sz + 1);
  len = strlen(sz + 1);
  for (int i = 1; i <= len + 3; i++) dp[i] = inf;
  dp[0] = 0;
  for (int i = 1; i <= len; i++) {
    long long now = 0;
    for (int j = i; j <= len; j++) {
      now = now * 10 + (sz[j] - '0');
      if (now >= n) break;
      if (sz[i] == '0' && j > i) break;
      if (1.0 * dp[i - 1] * n + now > 2e18 + 1000) break;
      dp[j] = min(dp[j], dp[i - 1] * n + now);
    }
  }
  cout << dp[len] << endl;
  return 0;
}
