N = int(input())
count = int(0)
for i in range(0, N):
    judge = False
    if str(i).find("357") > -1 or str(i).find("375") > -1 or str(i).find("537") > -1 or str(i).find("573") > -1 or str(i).find("735")  > -1 or str(i).find("753") > -1:
        judge = True
    if str(i).find("0") > -1:
        judge = False
    if str(i).find("1") > -1:
        judge = False
    if str(i).find("2") > -1:
        judge = False
    if str(i).find("4") > -1:
        judge = False
    if str(i).find("6") > -1:
        judge = False
    if str(i).find("8") > -1:
        judge = False
    if str(i).find("9") > -1:
        judge = False
    if judge == True:
        count += 1
print(count)