#!/usr/bin/env python

N = int(raw_input())
Array3 = [[] for i in range(9)]
Array5 = [[] for i in range(9)]
Array7 = [[] for i in range(9)]
Array53 = [[] for i in range(9)]
Array75 = [[] for i in range(9)]
Array73 = [[] for i in range(9)]
Array753 = [[] for i in range(9)]
Array3[0].append(3)
Array5[0].append(5)
Array7[0].append(7)
Arraytot = []

for i in range(8):
    Array753[i+1].extend(map(lambda x: x*10+7, Array753[i]))
    Array753[i+1].extend(map(lambda x: x*10+5, Array753[i]))
    Array753[i+1].extend(map(lambda x: x*10+3, Array753[i]))
    Array753[i+1].extend(map(lambda x: x*10+3, Array75[i]))
    Array753[i+1].extend(map(lambda x: x*10+5, Array73[i]))
    Array753[i+1].extend(map(lambda x: x*10+7, Array53[i]))
    Array75[i+1].extend(map(lambda x: x*10+5, Array75[i]))
    Array75[i+1].extend(map(lambda x: x*10+7, Array75[i]))
    Array75[i+1].extend(map(lambda x: x*10+7, Array5[i]))
    Array75[i+1].extend(map(lambda x: x*10+5, Array7[i]))
    Array73[i+1].extend(map(lambda x: x*10+3, Array73[i]))
    Array73[i+1].extend(map(lambda x: x*10+7, Array73[i]))
    Array73[i+1].extend(map(lambda x: x*10+7, Array3[i]))
    Array73[i+1].extend(map(lambda x: x*10+3, Array7[i]))
    Array53[i+1].extend(map(lambda x: x*10+3, Array53[i]))
    Array53[i+1].extend(map(lambda x: x*10+5, Array53[i]))
    Array53[i+1].extend(map(lambda x: x*10+5, Array3[i]))
    Array53[i+1].extend(map(lambda x: x*10+3, Array5[i]))
    Array3[i+1].extend(map(lambda x:x*10+3, Array3[i]))
    Array5[i+1].extend(map(lambda x:x*10+5, Array5[i]))
    Array7[i+1].extend(map(lambda x:x*10+7, Array7[i]))
    Arraytot.extend(Array753[i+1])

Arraytot.sort()
ans = 0
for i in Arraytot:
    if i <= N:
        ans+=1
    else:
        break
print ans