#include <bits/stdc++.h>
using namespace std;
long long d[100][100], c[100], ans, p;
int main() {
  string s, t;
  cin >> s >> t;
  long long n = t.length(), m = s.length();
  t = " " + t;
  for (long long i = 0; i < m; i++) {
    p = p * 10 + (s[i] - '0');
  }
  memset(d, 0x3f, sizeof(d));
  for (long long i = 1; i <= n; i++) {
    for (long long j = i; j <= n; j++) {
      if (j - i + 1 == 1)
        d[i][j] = 1;
      else {
        if (t[i] == '0' || j - i + 1 > m) continue;
        if (j - i + 1 < m)
          d[i][j] = 1;
        else if (j - i + 1 == m) {
          string p = t.substr(i, j - i + 1);
          if (p < s) d[i][j] = 1;
        }
      }
    }
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j < i; j++) {
      if (d[1][i] > d[1][j] + d[j + 1][i]) {
        d[1][i] = d[1][j] + d[j + 1][i];
        c[i] = j;
      }
    }
  }
  long long now = n, num = 1;
  while (now > 0) {
    long long sum = 0;
    for (long long i = c[now] + 1; i <= now; i++) {
      sum = sum * 10 + (t[i] - '0');
    }
    ans += sum * num;
    now = c[now];
    num *= p;
  }
  cout << ans << endl;
}
