import Data.Maybe

main :: IO ()
main = do
  [n,m] <- map read . words <$> getLine
  s <- getLine
  t <- getLine
  putStrLn $ fromMaybe "-1" $ solve n m s t

solve :: Int -> Int -> String -> String -> Maybe String
solve n m s t = if b then Just (build p str) else Nothing
  where
    l = lcm n m
    n' = l `div` n
    m' = l `div` m
    l' = lcm n' m'
    b = all (\(i,j) -> s !! i == t !! j) [(p`div`n',p`div`m') | x <- [0..(l`div`l'-1)], let p = x*l']
    (str,p) = if n > m then (s,n') else (t,m')

build :: Int -> String -> String
build p str = concat [s:(replicate (p-1) 'a') | s <- str]
