import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Array as A

main :: IO ()
main = do
  (n : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  xs <- map (read . pure) <$> getLine :: IO [Int]
  print . length . filter (p xs) . sequence . replicate 3 $ [0..9]

p :: [Int] -> [Int] -> Bool
p = \xs -> maybe False (const True) . p' xs
  where
    p' :: [Int] -> [Int] -> Maybe ()
    p' _ [] = Just ()
    p' [] _ = Nothing
    p' xs (i : is) = f i xs >>= flip p' is

f :: Int -> [Int] -> Maybe [Int]
f i xs = case dropWhile (/= i) xs of _ : xs' -> Just xs'; _ -> Nothing

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n
