n = input()
N = int(n)

a = int((n[-3:]))

y = 0
if a >= 753:
    x = 6
elif a >= 735:
    x = 5
elif a >= 573:
    x = 4
elif a >= 537:
    x = 3
elif a >= 375:
    x = 2
elif a >= 357:
    x = 1
elif a < 356:
    x =0

for i in range(0, len(n)-3):
    if int(n[i]) == 0:
        y = y
    elif int(n[i]) >=7:
        y += (len(n) - i) * 3 - 9
    elif int(n[i]) >=5:
        y += (len(n) - i) * 3 - 10
    elif int(n[i]) >= 3:
        y += (len(n) - i) * 3 - 11
    elif int(n[i]) == 2 or 1:
        y += (len(n) - i) * 3 - 12

print(x + y)
