#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int INF = 1e9;
char string_con[70];
int n;
int main() {
  while (~scanf("%d", &n)) {
    getchar();
    scanf("%s", string_con);
    int len_con = strlen(string_con);
    int i = len_con - 1;
    long long mid = 1, ans = 0, tmp = 1, when = 0;
    int flag = 0;
    while (i >= 0) {
      if (!flag) mid = 1;
      flag = 0;
      int j = i;
      when = 0;
      while (j >= 0) {
        if (mid >= n) {
          flag = 1;
          break;
        }
        if (when + (string_con[j] - '0') * mid >= n) {
          if ((mid / 10) > when && i != j) flag = 1;
          break;
        }
        when += (string_con[j] - '0') * mid;
        mid *= 10;
        j--;
      }
      ans += when * tmp;
      if (flag) {
        if (when == 0) {
          mid /= 10;
        } else {
          while (when) {
            when /= 10;
            mid /= 10;
          }
        }
      }
      tmp *= n;
      i = j;
    }
    printf("%lld\n", ans);
  }
}
