{-# LANGUAGE BangPatterns #-}

import qualified Data.List as L

import Control.Monad

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

solve :: Int -> Int -> [Int] -> [Int] -> Int
solve h w ps qs = connect ps' qs' (h + 1) (w + 1) id
  where
    ps' = L.sort ps
    qs' = L.sort qs
    connect :: [Int] -> [Int] -> Int -> Int -> (Int -> Int) -> Int
    connect [] [] = (.) ((.) ($ 0)) . const . flip const
    connect ps [] = onSN ps []
    connect [] qs = onEW [] qs
    connect ps qs = go   ps qs
      where
        go = if head ps <= head qs then onSN else onEW
    onSN (p : ps) qs !y !x cont = connect ps qs (pred y) x $ cont . (p * x +)
    onEW ps (q : qs) !y !x cont = connect ps qs y (pred x) $ cont . (q * y +)
