#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powMod(long long x, long long y) {
  long long p = 1;
  while (y) {
    if (y % 2) {
      p = (p * x) % mod;
    }
    y /= 2;
    x = (x * x) % mod;
  }
  return p;
}
long long invMod(long long x) { return powMod(x, mod - 2); }
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long nCr(long long n, long long r) {
  if (n < r) return 0;
  long long nfac = 1;
  long long dfac = 1;
  for (long long i = n - r + 1; i <= n; i++) {
    nfac = (nfac * i) % mod;
  }
  for (long long i = 1; i <= r; i++) {
    dfac = (dfac * invMod(i)) % mod;
  }
  return (nfac * dfac) % mod;
}
vector<int> b(100005);
long long dp[2005][2005] = {0};
int solve() {
  string n;
  cin >> n;
  string s;
  cin >> s;
  string temp = "";
  long long nn = stoi(n);
  int nlength = n.length();
  long long x = 1;
  long long bits = 0;
  vector<string> ans;
  int zero = 0;
  int digit = 0;
  int i = s.length();
  while (i > 0) {
    i--;
    temp = s[i] + temp;
    if (temp.length() == nlength) {
      if (temp < n) {
        int flag = temp.length() - 1;
        for (long long j = 0; j < temp.length() - 1; j++) {
          if (temp[j] != '0') {
            flag = j;
            break;
          }
        }
        ans.push_back(temp.substr(flag));
        temp = "";
        i += flag;
      } else {
        int flag = temp.length() - 1;
        for (long long j = 1; j < temp.length() - 1; j++) {
          if (temp[j] != '0') {
            flag = j;
            break;
          }
        }
        ans.push_back(temp.substr(flag));
        temp = "";
        i += flag;
      }
    } else if (i == 0) {
      ans.push_back(temp);
    }
  }
  long long finalans = 0;
  for (long long i = 0; i < ans.size(); i++) {
    long long x = stoi(ans[i]);
    finalans += (long long)x * (long long)pow(nn, i);
    cerr << x * (long long)pow(nn, i) << endl;
  }
  cout << finalans << endl;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  solve();
  return 0;
}
