#include <bits/stdc++.h>
using namespace std;
const long long MAX = 65;
deque<long long> num;
long long base;
long long szBase;
deque<long long> getDeque(string &s) {
  deque<long long> x;
  for (long long i = 0; i < (long long)s.size(); i++) {
    x.push_back(s[i] - '0');
  }
  return x;
}
long long getSize(long long x) {
  if (x == 0) {
    return 1;
  }
  long long cnt = 0;
  while (x > 0) {
    cnt++;
    x /= 10;
  }
  return cnt;
}
long long memo[MAX];
bool used[MAX];
const long long INF = 5e18;
long long getNumber(long long i, long long j) {
  long long resp = 0;
  for (long long k = i; k <= j; k++) {
    resp = resp * 10 + num[k];
  }
  return resp;
}
long long minVal(long long pos) {
  if (pos < 0) {
    return 0;
  }
  long long &ans = memo[pos];
  if (used[pos]) {
    return ans;
  }
  used[pos] = true;
  ans = INF;
  long long i = pos;
  while (i >= 0 && (pos - i + 1) <= szBase && getNumber(i, pos) < base) {
    long long x = minVal(i - 1);
    if (x > INF / base) {
      i--;
      continue;
    }
    if (num[i] == 0 && i != pos) {
      i--;
      continue;
    }
    ans = min(ans, x * base + getNumber(i, pos));
    i--;
  }
  return ans;
}
void doit() {
  cin >> base;
  szBase = getSize(base);
  string s;
  cin >> s;
  if (s == "0") {
    cout << 0 << endl;
    return;
  }
  num = getDeque(s);
  long long sz = num.size();
  cout << minVal(sz - 1) << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  doit();
  return 0;
}
