import Data.Char

solve :: Int -> Int -> Int
solve n m 
    | m > n = 0
    | (length $ show m) < 3 = solve'
    | check = 1 + solve'
    | otherwise = solve'
        where
            xs = map digitToInt $ show m
            check = (elem 7 xs) && (elem 5 xs) && (elem 3 xs)
            solve' = (solve n (m*10+7)) + (solve n (m*10+5)) + (solve n (m*10+3))