# -*- coding: utf-8 -*-
def next_set(nums, digit):
    r = set()
    for num in nums:
        for v in ["3", "5", "7"]:
            r.add(v+num)            
            for i in range(1,len(num)):
                n = list(num)
                n.insert(i, v)
                r.add("".join(n))
            r.add(num+v)
    return r


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

if len(str(s)) < 3:
    print(0)
else:
    count = sum(int(num)<s for num in nums)
    for i in range(len(str(s)) - 3):
        nums = next_set(nums, i+4)
        count += sum(int(num)<s for num in nums)
    print(count)