use std::collections::VecDeque;

const INF: i64 = 1 << 50;
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let m: usize = sc.read();

    let mut vx = vec![-INF, 0, INF];
    let mut vy = vec![-INF, 0, INF];

    let mut x_lines = vec![];
    for _ in 0..n {
        let x1: i64 = sc.read();
        let x2: i64 = sc.read();
        let y: i64 = sc.read();
        x_lines.push((x1, x2, y));
        vx.push(x1);
        vx.push(x2);
        vy.push(y);
    }

    let mut y_lines = vec![];
    for _ in 0..m {
        let x: i64 = sc.read();
        let y1: i64 = sc.read();
        let y2: i64 = sc.read();
        y_lines.push((y1, y2, x));
        vy.push(y1);
        vy.push(y2);
        vx.push(x);
    }

    vx.sort();
    vx.dedup();
    vy.sort();
    vy.dedup();

    let h = vx.len();
    let w = vy.len();

    let mut x_wall = vec![vec![]; w];
    for &(x1, x2, y) in x_lines.iter() {
        let x1 = vx.binary_search(&x1).unwrap();
        let x2 = vx.binary_search(&x2).unwrap();
        let y = vy.binary_search(&y).unwrap();
        x_wall[y].push((x1, x2));
    }

    for x_wall in x_wall.iter_mut() {
        x_wall.sort();
    }

    let mut y_wall = vec![vec![]; h];
    for &(y1, y2, x) in y_lines.iter() {
        let y1 = vy.binary_search(&y1).unwrap();
        let y2 = vy.binary_search(&y2).unwrap();
        let x = vx.binary_search(&x).unwrap();
        y_wall[x].push((y1, y2));
    }

    for y_wall in y_wall.iter_mut() {
        y_wall.sort();
    }

    let mut board = vec![vec![false; w - 1]; h - 1];

    let si = vx.binary_search(&0).unwrap();
    let sj = vy.binary_search(&0).unwrap();
    board[si][sj] = true;
    let mut queue = VecDeque::new();
    queue.push_back((si, sj));
    while let Some((x, y)) = queue.pop_front() {
        if x > 0 {
            let conflict = wall(&y_wall[x], y);
            if !board[x - 1][y] && !conflict {
                board[x - 1][y] = true;
                queue.push_back((x - 1, y));
            }
        }

        if x + 1 < board.len() {
            let conflict = wall(&y_wall[x + 1], y);
            if !board[x + 1][y] && !conflict {
                board[x + 1][y] = true;
                queue.push_back((x + 1, y));
            }
        }

        if y > 0 {
            let conflict = wall(&x_wall[y], x);
            if !board[x][y - 1] && !conflict {
                board[x][y - 1] = true;
                queue.push_back((x, y - 1));
            }
        }

        if y + 1 < board[x].len() {
            let conflict = wall(&x_wall[y + 1], x);
            if !board[x][y + 1] && !conflict {
                board[x][y + 1] = true;
                queue.push_back((x, y + 1));
            }
        }
    }

    let mut ans = 0;
    for x in 0..board.len() {
        for y in 0..board[x].len() {
            if !board[x][y] {
                continue;
            }

            if x == 0 || x == board.len() - 1 || y == 0 || y == board[x].len() - 1 {
                println!("INF");
                return;
            }

            let x1 = vx[x];
            let x2 = vx[x + 1];
            let y1 = vy[y];
            let y2 = vy[y + 1];
            ans += (x2 - x1) * (y2 - y1);
        }
    }

    println!("{}", ans);
}

fn wall(walls: &Vec<(usize, usize)>, x: usize) -> bool {
    let mut conflict = false;
    let right = walls.binary_search(&(x, 0)).err().unwrap();
    if walls.len() > right {
        let (x1, x2) = walls[right];
        if x1 <= x && x + 1 <= x2 {
            conflict = true;
        }
    }

    if right > 0 && walls.len() > right - 1 {
        let (x1, x2) = walls[right - 1];
        if x1 <= x && x + 1 <= x2 {
            conflict = true;
        }
    }
    conflict
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 11416