d = list(map(int, input().split()))
a = int(input())
answer = 0
for i in range(1, a + 1):
    x = 0
    for k in range(len(d)):
        if str(d[k]) in str(i):
            x = 1
            break
        if x == 0 and d[k] == d[-1]:
            answer += 1          
print(answer)
