#include <bits/stdc++.h>
using namespace std;
const int N = 110, M = 1e9 + 10;
const long long inf = 1LL << 60;
long long dp[N][N], res, val[N][N];
void init(const string& s) {
  int n = s.length();
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      long long v = 0;
      for (int k = i; k <= j; k++) {
        v = v * 10 + (s[k] - '0');
        if (v > M) break;
      }
      val[i][j] = v;
    }
  }
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) dp[i][j] = inf;
}
int main() {
  int n;
  string s;
  cin >> n >> s;
  int m = s.length();
  if (n <= 10) {
    for (int i = 0; i < m; i++) res = res * n + (s[i] - '0');
  } else {
    init(s);
    dp[0][0] = 0;
    for (int i = 0; i < m; i++) {
      for (int j = i + 1; j <= m; j++) {
        if (val[i][j - 1] >= n) break;
        if (j - i > 1 && s[i] == '0') break;
        for (int k = 0; k <= m; k++)
          if (dp[i][k] < inf / n) {
            long long& t = dp[j][k + 1];
            t = min(t, dp[i][k] * n + val[i][j - 1]);
          }
      }
    }
    res = inf;
    for (int i = 0; i <= m; i++) res = min(res, dp[m][i]);
  }
  cout << res << endl;
  return 0;
}
