use proconio::input;
use itertools::Itertools;

const INF:i64 = 1e16 as i64;

fn main() {
    input! {
        n:usize,
        m:usize,
        abc:[(i64,i64,i64);n],
        def:[(i64,i64,i64);m],
    };

    let xs:Vec<i64> = {
        let mut vec = Vec::<i64>::new();
        vec.push(0);
        vec.push(INF);
        vec.push(-INF);
        abc.iter().for_each(|&(a,b,_)|{
            vec.push(a);
            vec.push(b);
        });
        def.iter().for_each(|&(d,_,_)|{
            vec.push(d);
        });
        vec.sort();
        vec.into_iter().unique().collect()
    };
    let ys:Vec<i64> = {
        let mut vec = Vec::<i64>::new();
        vec.push(0);
        vec.push(INF);
        vec.push(-INF);
        abc.iter().for_each(|&(_,_,c)|{
            vec.push(c);
        });
        def.iter().for_each(|&(_,e,f)|{
            vec.push(e);
            vec.push(f);
        });
        vec.sort();
        vec.into_iter().unique().collect()
    };
    
    let gridx = {
        let mut gridx = vec![vec![false;ys.len()];xs.len()];
        for &(a,b,c) in &abc {
            let j = ys.iter().position(|&y|y==c).unwrap();
            for i in 0..xs.len() {
                if a<=xs[i] && xs[i]<b {
                    gridx[i][j] = true
                }
            }
        }
        gridx
    };

    let gridy = {
        let mut gridy = vec![vec![false;ys.len()];xs.len()];
        for &(d,e,f) in &def {
            let i = xs.iter().position(|&x|x==d).unwrap();
            for j in 0..ys.len() {
                if e<=ys[j] && ys[j]<f {
                    gridy[i][j] = true
                }
            }
        }
        gridy
    };

    let mut grid = vec![vec![false;ys.len()-1];xs.len()-1];
    let mut stack = Vec::<(usize,usize)>::new();
    {
        let (i,j) = {
            (
            xs.iter().position(|&x|x==0).unwrap(),
            ys.iter().position(|&y|y==0).unwrap(),
            )
        };
        grid[i][j] = true;
        stack.push((i,j));
    }

    let di = vec![1,0,-1,0];
    let dj = vec![0,1,0,-1];

    while let Some((i,j)) = stack.pop() {
        if i==0 || j==0 || i==xs.len()-1 || j==ys.len()-1 {
            println!("INF");
            return;
        }
        for k in 0..4 {
            let gi = i+(di[k]+1) as usize/2;
            let gj = j+(dj[k]+1) as usize/2;
            let xwall = dj[k]!=0 && gridx[gi][gj];
            let ywall = di[k]!=0 && gridy[gi][gj];
            let toi = (i as i32 +di[k]) as usize;
            let toj = (j as i32 +dj[k]) as usize;
            if !xwall && !ywall && !grid[toi][toj]{
                grid[toi][toj] = true;
                stack.push((toi,toj));
            }
        }
    }

    let mut ans = 0;
    for i in 0..xs.len()-1 {
        for j in 0..ys.len()-1 {
            if grid[i][j] {
                let xwid = xs[i+1]-xs[i];
                let ywid = ys[j+1]-ys[j];
                ans += xwid*ywid;
            }
        }
    }
    println!("{}",ans);

}
