import Control.Monad
import Control.Arrow
import Control.Applicative

rotate :: Int -> String -> String
rotate 0 t = t
rotate n t = drop n t ++ take n t

cand :: Int -> String -> Int -> [String]
cand 0 xs _ = []
cand n xs tlen = (take tlen xs) : cand (n-1) (rotate 1 xs) tlen

main :: IO ()
main = do
  target <- getLine
  n <- read <$> getLine :: IO Int

  ringStrs <- forM [1..n] $ \_ -> do
    getLine

  let css = map (flip (uncurry cand) $ length target) $
            map (length &&& id) ringStrs

  putStrLn $ show $ length $ filter (==True) $ map (elem target) css