#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll val(char c){
return c-'0';
}
int main()
{
ll n;
string k;
cin >> n >> k;
ll pos = k.size()-1;
ll mul = 1;
ll res = 0;
while(pos >= 0){
ll cu = 0;
ll mu = 1;
for(int i=pos+1; i<k.size() && k[i] == '0'; i++){
mul *= n;
}
while(pos >= 0 && val(k[pos])*mu+cu < n){
cu = val(k[pos])*mu+cu;
pos--;
mu *= 10;
}
res += cu*mul;
mul *= n;
}
cout << res << endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnR5cGVkZWYgbG9uZyBsb25nIGxsOwoKbGwgdmFsKGNoYXIgYyl7CiAgICByZXR1cm4gYy0nMCc7Cn0KaW50IG1haW4oKQp7CiAgICBsbCBuOwogICAgc3RyaW5nIGs7CgogICAgY2luID4+IG4gPj4gazsKICAgIGxsIHBvcyA9IGsuc2l6ZSgpLTE7CiAgICBsbCBtdWwgPSAxOwogICAgbGwgcmVzID0gMDsKICAgIHdoaWxlKHBvcyA+PSAwKXsKICAgICAgICBsbCBjdSA9IDA7CiAgICAgICAgbGwgbXUgPSAxOwogICAgICAgIGZvcihpbnQgaT1wb3MrMTsgaTxrLnNpemUoKSAmJiBrW2ldID09ICcwJzsgaSsrKXsKICAgICAgICAgICAgbXVsICo9IG47CiAgICAgICAgfQogICAgICAgIHdoaWxlKHBvcyA+PSAwICYmIHZhbChrW3Bvc10pKm11K2N1IDwgbil7CiAgICAgICAgICAgIGN1ID0gdmFsKGtbcG9zXSkqbXUrY3U7CiAgICAgICAgICAgIHBvcy0tOwogICAgICAgICAgICBtdSAqPSAxMDsKICAgICAgICB9CiAgICAgICAgcmVzICs9IGN1Km11bDsKICAgICAgICBtdWwgKj0gbjsKICAgIH0KICAgIGNvdXQgPDwgcmVzIDw8IGVuZGw7CgogICAgcmV0dXJuIDA7Cn0K