#include <bits/stdc++.h>
using namespace std;
template <class T>
void dbs(string str, T t) {
  cerr << str << " : " << t << "\n";
}
template <class T, class... S>
void dbs(string str, T t, S... s) {
  int idx = str.find(',');
  cerr << str.substr(0, idx) << " : " << t << ",";
  dbs(str.substr(idx + 1), s...);
}
template <class S, class T>
ostream& operator<<(ostream& os, const pair<S, T>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
void debug(T a, T b) {
  cerr << "[";
  for (T i = a; i != b; ++i) {
    if (i != a) cerr << ", ";
    cerr << *i;
  }
  cerr << "]\n";
}
const long long INF = 2e18 + 10;
long long dp[111];
long long a[111];
long long n;
long long go(int idx) {
  if (idx < 0) {
    return 0ll;
  }
  long long& ret = dp[idx];
  if (~ret) {
    return ret;
  }
  ret = INF;
  long long p = 1;
  long long cur = 0;
  for (int i = idx; i >= 0; --i) {
    cur += p * a[i];
    if (cur >= n) {
      break;
    }
    if (a[i] > 0 or i == idx) {
      long long tmp = go(i - 1);
      if ((long double)tmp * n + cur <= INF) {
        ret = min(ret, tmp * n + cur);
      }
    } else if (p >= n) {
      break;
    }
    p *= 10;
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < int(s.size()); ++i) {
    a[i] = s[i] - '0';
  }
  memset(dp, -1, sizeof(dp));
  cout << go(int(s.size()) - 1) << "\n";
  return 0;
}
