# -*- coding: utf-8 -*-
import copy 

def mul(nums, digit):
    r = []
    for num in nums:
        for v in ["3", "5", "7"]:
            r.append(v+num)            
            for i in range(1,len(num)):
                n = list(num)
                n.insert(i, v)
                r.append("".join(copy.deepcopy(n)))
            r.append(num+v)
    return r


nums = ["357", "375", "537", "573", "735", "753"]
s = input()

if len(s) < 3:
    print(0)
elif len(s) == 3:
    count = 0
    for v in nums:
        if int(s) > int(v):
            count += 1
    print(count)
else:
    count = 0
    for i in range(len(s) - 3):
        nums = list(set(mul(nums, i+4)))
    s = int(s)
    print(sum(int(num)<s for num in set(nums)))