#![allow(unused_imports)]

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::{min, max};
use std::collections::{HashMap, HashSet};

fn main() {
    input!{
        n: usize,
        m: usize,
        v: [(i64, i64, i64); n],
        w: [(i64, i64, i64); m]
    }
    let mut xs = vec![];
    let mut ys = vec![];
    for &(a, b, c) in &v {
        xs.push(a);
        xs.push(b);
        ys.push(c);
    }
    for &(d, e, f) in &w {
        xs.push(d);
        ys.push(e);
        ys.push(f);
    }

    xs.sort();
    xs.dedup();
    ys.sort();
    ys.dedup();
    let mut g = vec![vec![0; ys.len() + 1]; xs.len() + 1];
    let mut ar = vec![vec![-1; ys.len() + 1]; xs.len() + 1];
    for i in 1..xs.len() {
        for j in 1..ys.len() {
            ar[i][j] = (xs[i] - xs[i - 1]) * (ys[j] - ys[j - 1]);
        }
    }
    for &(a, b, c) in &v {
        let xl = xs.binary_search(&a).unwrap();
        let xr = xs.binary_search(&b).unwrap();
        let y = ys.binary_search(&c).unwrap();
        for i in xl + 1..=xr {
            g[i][y] |= 8;
            g[i][y + 1] |= 4;
        }
    }
    for &(d, e, f) in &w {
        let x = xs.binary_search(&d).unwrap();
        let yl = ys.binary_search(&e).unwrap();
        let yr = ys.binary_search(&f).unwrap();
        for i in yl + 1..=yr {
            g[x][i] |= 2;
            g[x + 1][i] |= 1;
        }
    }
    let x0 = match xs.binary_search(&0) {Ok(i) => i, Err(i) => i};
    let y0 = match ys.binary_search(&0) {Ok(i) => i, Err(i) => i};
    if ar[x0][y0] == -1 {
        println!("INF");
        return;
    }
    let mut st = vec![(x0, y0)];
    let mut done = vec![vec![false; ys.len() + 1]; xs.len() + 1];
    let mut ans = ar[x0][y0];
    done[x0][y0] = true;
    while let Some((i, j)) = st.pop() {
        let con = g[i][j];
        if con & 1 == 0 && !done[i - 1][j] {
            if ar[i - 1][j] == -1 {
                println!("INF");
                return;
            }
            ans += ar[i - 1][j];
            st.push((i - 1, j));
            done[i - 1][j] = true;
        }
        if con & 2 == 0 && !done[i + 1][j] {
            if ar[i + 1][j] == -1 {
                println!("INF");
                return;
            }
            ans += ar[i + 1][j];
            st.push((i + 1, j));
            done[i + 1][j] = true;
        }
        if con & 4 == 0 && !done[i][j - 1] {
            if ar[i][j - 1] == -1 {
                println!("INF");
                return;
            }
            ans += ar[i][j - 1];
            st.push((i, j - 1));
            done[i][j - 1] = true;
        }
        if con & 8 == 0 && !done[i][j + 1] {
            if ar[i][j + 1] == -1 {
                println!("INF");
                return;
            }
            ans += ar[i][j + 1];
            st.push((i, j + 1));
            done[i][j + 1] = true;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 176116