'use strict'

function main(s) {

  s = s.split('\n');

  const w = Number(s[0].split(' ')[0]);
  const h = Number(s[0].split(' ')[1]);

  const xyas = s.slice(1, -1).map(l => l.split(' ').map(n => Number(n)));

  const bucket = [...Array(h)].map(l => [...Array(w)].fill(0));

  for (const xya of xyas) {
    const x = xya[0];
    const y = xya[1];
    const a = xya[2] - 1;

    const fromH = [0, 0, 0, y];
    const toH   = [h, h, y, h];
    const fromW = [0, x, 0, 0];
    const toW   = [x, w, w, w];

    for (let i = fromH[a]; i < toH[a]; i++) {
      for (let j = fromW[a]; j < toW[a]; j++) {
        bucket[i][j] = 1;
      }
    }
  }

  let count = 0;
  for (let i = 0; i < h; i++) {
    for (let j = 0; j < w; j++) {
      if (bucket[i][j] === 0) count += 1;
    }
  }

  console.log(count);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
