#再帰関数
N = int(input())
def sft(s):
    if int(s) > N:
        return 0
    cnt = 1 if all(s.count(c)>0 for c in '753') else 0
    for c in '753':
        cnt += sft(s+c)
    return cnt
    
print(sft('0'))