#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e2 + 20;
char str[maxn];
long long int po[maxn];
void work() {
  po[0] = 1;
  for (int i = 1; i <= 18; ++i) po[i] = po[i - 1] * 10;
  int n;
  cin >> n;
  cin >> str + 1;
  int lenstr = strlen(str + 1);
  int be = lenstr;
  int k = 0;
  long long int ans = 0;
  long long int t = 0;
  int how = 0;
  for (int i = lenstr; i >= 1; --i) {
    t += (str[i] - '0') * po[be - i];
    if (be - i > 18) {
      t = 1e18L;
    }
    if (t >= n) {
      int pos = (0x3f3f3f3f);
      for (int j = i + 1; j <= be; ++j) {
        if (str[j] != '0') {
          pos = j;
          break;
        }
      }
      t = 0;
      for (int j = be; j >= pos; --j) {
        t += (str[j] - '0') * po[be - j];
      }
      long long int add = 1;
      for (int j = 1; j <= how; ++j) {
        add *= n;
      }
      how++;
      ans += t * add;
      t = 0;
      if (pos == (0x3f3f3f3f))
        be--;
      else
        be = pos - 1;
      i = be + 1;
    }
    if (i == 1) {
      long long int add = 1;
      for (int i = 1; i <= how; ++i) {
        add *= n;
      }
      ans += add * t;
      break;
    }
  }
  cout << ans << endl;
}
int main() {
  work();
  return 0;
}
