#include <iostream>
#include <stdio.h>

using namespace std;

#define MAXN 100

int N[MAXN];
int res, k, l, m;
int A[MAXN];
char c, x;

int main(void)
{
    int i=0;
    while ((scanf("%c%c", &c, &x) == 2) && (x != '\n')) { A[c-48] = -1; k++; }
    A[c-48] = -1; k++;
    i=0;
    while ((scanf("%c", &c) == 1) && (c != '\n')) { N[i] = c-48; i++; l++; }
    res = 1;
    for (int h=1; h<=(l-1); h++){
        m=0;
        for (int j=0; j<=N[h]; j++) {
            if (A[j] == 0) m++;
        }
        res *= m;
    }
        for (int j=0; j<N[0]; j++) {
            if (A[j] == 0) res+=(10-k);
        }
    cout << res-1 << endl;
    return 0;
}
