#include <iostream>
using namespace std;

int a[9], k;

bool check (int x){
    while (x){
        for (int i = 0; i < k; i++){
            if (x%10 == a[i])
                return 0;
        }
        x /= 10;
    }

    return 1;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    for (int i = 0; i < 9; i++)
        a[i] = -1;

    while (cin >> a[k])
        k++;

    k--;
    int t = a[k];
    a[k] = -1;

    int q(0);

    for (int i = 0; i <= t; i++){
        if (check(i))
            q++;
    }

    cout << q-1;
}
