import Control.Monad (replicateM)
import Data.List (sortBy)
import Data.Ord (comparing)

data Direction = Parallel | Orthogonal deriving (Enum, Show)
type Edge a = (a, Direction)

minCost :: Integral a => a -> a -> [Edge a] -> [Edge a] -> a
minCost w h ps qs = f (w + 1) (h + 1) 0 edges
    where
        edges = sortBy (comparing fst) $ ps ++ qs
        f _ _ r [] = r
        f a b r (e : es) = case e of
            (x, Parallel) -> f (a - 1) b (r + b * x) es
            (x, Orthogonal) -> f a (b - 1) (r + a * x) es

main :: IO ()
main = do
    [w, h] <- fmap read . words <$> getLine
    ps <- fmap ((\x -> (x, Parallel)) . read) <$> replicateM w getLine
    qs <- fmap ((\x -> (x, Orthogonal)) . read) <$> replicateM h getLine
    print $ minCost w h ps qs
