palindrome :: Int -> [Int] palindrome d = map (foldr (\x acc -> x + acc * 10) 0) $ palindrome' d 1 where palindrome' 1 i = [ [x] | x <- [i..9] ] palindrome' 2 i = [ [x, x] | x <- [i..9] ] palindrome' d i = [ x : (l ++ [x]) | x <- [i..9], l <- palindrome' (d-2) 0 ] pa = concat (map palindrome [1..9]) main = do n <- readLn print $ length $ filter (\m -> m * (10 ^ 9 + 1) <= n) pa