#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
using namespace std;
long long int x, b, ans = 0;
string second;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> b >> second;
  if (second[0] == '0') {
    return cout << 0, 0;
  }
  x = second.size() - 1;
  long long int res = 0, p = 1, q = 1;
  while (x >= 0) {
    while (x >= 0) {
      long long int y = x;
      while (second[x] == '0' && q <= 100000000000000000) {
        x--;
        q *= 10;
      }
      res += (second[x] - '0') * q;
      if (res >= b || q > 100000000000000000) {
        res -= (second[x] - '0') * q;
        ans += res * p;
        p *= b;
        q = 1;
        x = y;
        if (res == 0) {
          x--;
        }
        res = 0;
        break;
      }
      if (q <= 100000000000000000) {
        q *= 10;
      }
      x--;
    }
  }
  ans += res * p;
  cout << ans << '\n';
}
