#include <bits/stdc++.h>
using namespace std;
#define int long long

int combination(int n, int k){
  vector<vector<int>> comb(n + 1, vector<int>(k + 1, 0));
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= k && j <= i; j++){
//      printf("(i, j) = (%d, %d)\n", i, j);
      if(j == 0){
        comb[i][j] = 1;
      }
      else{
        comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
      }
//      printf("comb[%d][%d] = %d\n", i, j, comb[i][j]);
    }
  }
  return comb[n][k];
}

signed main(){
  int L;
  scanf("%lld", &L);
  printf("%lld\n", combination(L - 1, 11));
  return 0;
}
#include <bits/stdc++.h>
using namespace std;

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;

#define max(p, q) ((p) > (q) ? (p) : (q))
#define min(p, q) ((p) < (q) ? (p) : (q))

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)
#define repl(i, l, n) for (int i = (l), i##_len = (n); i < i##_len; i++)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define mp make_pair

#define has_key(m, k) (m.find(k) != m.end())

#define INF (1e9)
#define EPS (1e-7)

// 総数を1000000007（素数）で割った余り
const ll mod = (1000000007);

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

#include <unordered_set>
#include <unordered_map>
class Radix
{
private:
    unordered_map<char, ull> a;

public:
    Radix(const char *s = "0123456789")
    {
        int i;
        for (i = 0; s[i]; ++i)
            a[s[i]] = i;
    }
    ull to(const std::string &t, ull p)
    {
        ull sm = a[t[0]];
        const int l = (int)t.length();
        for (int i = 1; i < l; ++i)
            sm = sm * p + a[t[i]];
        return sm;
    }
};

int main()
{
    std::string X;
    std::cin >> X;
    ull M;
    cin >> M;

    const ull start = (*std::max_element(X.begin(), X.end())) - '0';
    ull min_n = start + 1;
    ull max_n = M;
    if(X.size() != 1)
        max_n = max(pow(M,1.0l/(X.size()-1)),start) + 1;
    Radix r;
    ull ans = 0;

    ull mid_n;

    if (X.size() == 1)
    {
        if (stoull(X) <= M)
        {
            ans = 1;
        }
    }
    else if (r.to(X, min_n) <= M)
    {
        while (max_n != min_n)
        {
            mid_n = (min_n + max_n) / 2;
            const ull val = r.to(X, mid_n);
            if (val <= M)
            {
                min_n = mid_n;
            }
            else
            {
                max_n = mid_n;
            }
            if (min_n + 1 == max_n)
            {
                if (r.to(X, max_n) > M)
                {
                    max_n = min_n;
                }
                break;
            }
        }
        ans = max_n - start;
    }

cout << ans << endl;
return 0;
}
