import           Data.List

main :: IO ()
main = do
  getLine
  s <- getLine
  t <- getLine
  print $ solve s t

solve :: String -> String -> Int
solve s t = length $ head $ filter (s `isPrefixOf`) [ s' ++ t | s' <- inits s ]