#include <bits/stdc++.h>
using namespace std;
inline long long fmod(long long a) {
  if (a >= 0 && a < 1000000007) return a;
  a %= 1000000007;
  if (a < 1000000007) a += 1000000007;
  return a;
}
char S[100];
int main() {
  long long n;
  scanf("%lld", &n);
  long long ans = 0;
  scanf("%s", S);
  int len = strlen(S);
  long long base = 0;
  long long temp = 1;
  long long thisFar = 0;
  int nlen = 0;
  long long tn = n;
  while (tn) {
    tn /= 10;
    nlen++;
  }
  int i = len - 1;
  while (i >= 0) {
    base = max(base * n, 1LL);
    int j = i;
    long long temp = 1;
    long long cval = 0;
    for (int k = nlen; j >= 0 && k > 0; k--) {
      cval += (S[j] - '0') * temp;
      if (cval >= n) {
        cval -= (S[j] - '0') * temp;
        break;
      }
      j--;
      temp *= 10;
    }
    int tnlen = i - j;
    if (S[j + 1] != '0') {
      ans += base * cval;
      i = j;
      continue;
    } else {
      ans += base * cval;
      i = j + 1;
      for (int k = 1; k < tnlen; k++) {
        if (S[i] != '0') {
          break;
        } else
          i++;
      }
      i--;
    }
  }
  cout << ans << endl;
  return 0;
  for (int i = len - 1; i >= 0; i--) {
    thisFar += (S[i] - '0') * temp;
    if (thisFar >= n || S[i] == '0') {
      thisFar -= (S[i] - '0') * temp;
      ans += base * thisFar;
      if (S[i] != '0') {
        temp = 10;
      } else {
        if (thisFar != 0) base *= n;
        temp = 1;
      }
      thisFar = S[i] - '0';
      base *= n;
    } else {
      temp *= 10;
    }
  }
  ans += base * thisFar;
  cout << ans << endl;
  return 0;
}
