import Data.List

main=do
    n<-readLn::IO Int
    print $ length $ filter (<=n) $ map read g

g = u $ sort $ concatMap m $ concatMap k [3..9]

u [x] = [x]
u (a:b:x)
    | a==b = u (b:x)
    | otherwise = a:u (b:x)

k n = [(a,b,c)|a<-[1..n-2],b<-[1..n-a-1],c<-[1..n-a-b]]

m :: (Int,Int,Int)->[String]
m (0,0,0) = [[]]
m (a,0,0) = map ('3':) (m (a-1,0,0))
m (0,b,0) = map ('5':) (m (0,b-1,0))
m (0,0,c) = map ('7':) (m (0,0,c-1))
m (0,b,c) = map ('5':) (m (0,b-1,c)) ++ map ('7':) (m (0,b,c-1))
m (a,0,c) = map ('3':) (m (a-1,0,c)) ++ map ('7':) (m (a,0,c-1))
m (a,b,0) = map ('3':) (m (a-1,b,0)) ++ map ('5':) (m (a,b-1,0))
m (a,b,c) = map ('3':) (m (a-1,b,c)) ++ map ('5':) (m (a,b-1,c)) ++ map ('7':) (m (a,b,c-1))