#include <bits/stdc++.h>
using namespace std;
const int N = 1100;
long long base;
long long baseWithBase;
char rawNum[N];
long long ans;
long long maxNum = 0;
long long maxPos = 0;
long long tempNum;
int cntWei(long long n) {
  int ans = 0;
  int temp = n;
  while (temp) {
    temp /= 10;
    ans++;
  }
  return ans;
}
void init() {
  baseWithBase = 0;
  ans = 0;
  maxNum = 0;
  maxPos = 0;
  tempNum = 0;
}
int main(void) {
  while (~scanf("%lld%s", &base, rawNum)) {
    init();
    int cnt = (int)cntWei(base);
    int len = (int)strlen(rawNum);
    baseWithBase = 1;
    for (int i = len - 1; i >= 0; i -= maxPos) {
      maxNum = 0;
      maxPos = 0;
      tempNum = 0;
      for (int k = cnt; k >= 1; k--) {
        tempNum = 0;
        if (i - k + 1 < 0) continue;
        for (int j = i - k + 1; j <= i; j++) {
          tempNum += rawNum[j] - '0';
          tempNum *= 10;
        }
        tempNum /= 10;
        if (tempNum >= base) {
          if (k == 1) {
            ans += tempNum * (baseWithBase);
            maxPos = 1;
            break;
          } else {
            continue;
          }
        }
        if (tempNum >= maxNum) {
          maxNum = tempNum;
          maxPos = k;
        }
      }
      ans += maxNum * (baseWithBase);
      baseWithBase *= base;
    }
    printf("%lld\n", ans);
  }
}
