#include <bits/stdc++.h>
using namespace std;
template <typename Iter>
ostream& _out(ostream& s, Iter a, Iter b) {
  for (auto it = a; it != b; it++) s << (it == a ? "" : " ") << *it;
  return s;
}
template <typename A, typename B>
ostream& operator<<(ostream& s, pair<A, B>& p) {
  return s << "(" << p.first << " , " << p.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, vector<T>& v) {
  return _out(s, v.begin(), v.end());
}
inline long long rit() {
  int key = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') key = -1;
    c = getchar();
  }
  long long x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * key;
}
int __ = 1;
unsigned long long dp[100][100], num[100][100];
long long power[100];
void init() {}
void read() {}
void solve() {}
char s[100];
int main() {
  long long n;
  cin >> n;
  scanf("%s", s + 1);
  power[0] = 1;
  for (int i = 1; i < 100; i++) {
    power[i] = power[i - 1] * n;
    if (power[i] < 0) {
      for (int j = i; j < 100; j++) power[j] = 1000000000000000001LL;
      break;
    }
  }
  int len = strlen(s + 1);
  for (int i = 1; i <= len; i++) num[i][i] = s[i] - '0';
  for (int i = 1; i <= len; i++) {
    for (int j = i + 1; j <= len; j++) {
      if (num[i][j - 1] == 1000000000000000001LL) {
        num[i][j] = 1000000000000000001LL;
        continue;
      }
      num[i][j] = num[i][j - 1] * 10 + s[j] - '0';
      if (num[i][j - 1] == 0) num[i][j] = 1000000000000000001LL;
      if (num[i][j] >= n) num[i][j] = 1000000000000000001LL;
    }
  }
  for (int i = 0; i <= len; i++) dp[0][i] = 0;
  for (int i = 1; i <= len; i++) {
    for (int j = 0; j <= len; j++) {
      dp[i][j] = 1000000000000000001LL;
      for (int k = 0; k < i; k++) {
        if (num[k + 1][i] == 1000000000000000001LL ||
            dp[k][j + 1] == 1000000000000000001LL)
          continue;
        dp[i][j] = min(dp[i][j], dp[k][j + 1] + num[k + 1][i] * power[j]);
        if (dp[i][j] < 0)
          cout << dp[k][j + 1] << " " << num[k + 1][i] << " " << power[j]
               << endl;
      }
    }
  }
  printf("%I64d\n", dp[len][0]);
  return 0;
}
