#include <bits/stdc++.h>
using namespace std;
long long dp[130][130], n;
string s;
long long rec(long long x, long long y, long long res) {
  if (x == s.size()) return 0;
  if (dp[x][y] != -1) return dp[x][y];
  long long ans = 1e18, i, num = 0, val, cc = 1, cnt = 0;
  for (i = x; i < s.size(); i++) {
    num = (s[i] - '0') * cc + num;
    cc *= 10;
    cnt++;
    if (num >= n) break;
    if (s[i] == '0' && cnt > 1) continue;
    val = rec(i + 1, y + 1, res * n);
    if (1e18 / num < res) continue;
    if (1e18 / res < num) continue;
    if (1e18 - val < num * res) continue;
    ans = min(ans, val + num * res);
  }
  return (dp[x][y] = ans);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> s;
  reverse(s.begin(), s.end());
  memset(dp, -1, sizeof(dp));
  cout << rec(0, 0, 1);
  return 0;
}
