import Data.List
main = getLine >>= main' . map read . words
    where
        main' (w : h : _) = getContents >>= print . calc . solve (0, w, 0, h) . map (map read . words) . lines
        solve = foldl' ff
        ff (x1, x2, y1, y2) (x : y : a : _)
            | a == 1 = (max x1 x, x2, y1, y2)
            | a == 2 = (x1, min x x2, y1, y2)
            | a == 3 = (x1, x2, max y1 y, y2)
            | otherwise = (x1, x2, y1, min y y2)
        calc (x1, x2, y1, y2)
            | x1 < x2 && y1 < y2 = (x2 - x1) * (y2 - y1)
            | otherwise = 0
