import Control.Applicative
import Control.Monad
import Data.IORef

func :: [[Int]] -> Int -> Int -> Int -> Int -> Int
func ((x:y:a:_):xs) r l d t =
  case a of
     1 -> func xs (max r x) l d t
     2 -> func xs r (min l x) d t
     3 -> func xs r l (max d y) t
     4 -> func xs r l d (min t y)
     otherwise -> 0
    
func [] r l d t = width*height
  where
    width = if l-r > 0 then l-r else 0
    height = if t-d > 0 then t-d else 0

main :: IO ()
main = do
  [w,h,n] <- return . map (read::String->Int) . words =<< getLine
  dat <- return . map (map (read::String->Int) . words) . lines =<< getContents
  print $ func dat 0 w 0 h

