import Control.Monad
import Data.List

main :: IO ()
main = do
    n <- read <$> getLine
    s <- replicateM n getLine
    m <- read <$> getLine
    t <- replicateM m getLine
    putStrLn $ show $ solve s t


solve :: [String] -> [String] -> Int
solve s t = max 0 $ maximum [match w s - match w t | w <- s]
    where match ws li = length $ elemIndices ws li