#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, cnt = 1, cur, tmp, ans = 0;
  string s;
  int i, j, k = 0, m;
  cin >> n >> s;
  cur = n;
  while (cur) {
    k++;
    cur /= 10;
  }
  int l = s.length();
  i = l - 1;
  while (i >= 0) {
    j = i;
    tmp = 1;
    cur = s[j] - '0';
    m = 1;
    while (j >= 0 && cur < n && m <= k) {
      tmp *= 10;
      m++;
      if (j > 0) cur = cur + (tmp * (s[j - 1] - '0'));
      j--;
    }
    if (cur >= n) {
      cur -= (tmp * (s[j] - '0'));
      j++;
      m--;
      while (s[j] == '0' && m > 1) {
        j++;
        m--;
      }
      j--;
    } else {
      while (s[j] == '0' && m > 1) {
        j++;
        m--;
      }
      j--;
    }
    ans += (cnt * cur);
    i = j;
    cnt *= (n);
  }
  cout << ans << endl;
  return 0;
}
