#include <bits/stdc++.h>
using namespace std;
long double esp = 1e-11;
const long double PI = acos((long double)-1);
const long long int INF = 0x3f3f3f3f3f3f3f3fll;
const int MOD = 1000000007ll;
const int maxn = 210100;
long long int dp[110];
char s[110];
long long int cal(int l, int r) {
  long long int ans = 0;
  for (int x = l; x <= r; x++) ans = ans * 10 + s[x] - '0';
  return ans;
}
long long int n, ma;
long long int dfs(int k) {
  if (k == -1) return 0;
  if (dp[k] != INF) return dp[k];
  if (dfs(k - 1) <= ma) dp[k] = min(dp[k], dfs(k - 1) * n + s[k] - '0');
  for (int x = k - 2; x >= -1 && k - x <= 12; x--)
    if (s[x + 1] != '0' && cal(x + 1, k) < n && dfs(x) <= ma)
      dp[k] = min(dp[k], dfs(x) * n + cal(x + 1, k));
  return dp[k];
}
int main() {
  memset(dp, 0x3f, sizeof(dp));
  scanf("%I64d%s", &n, s);
  ma = 1e18 / n;
  int len = strlen(s);
  printf("%I64d\n", dfs(len - 1));
  return 0;
}
