macro_rules !read_value {($iter :expr ,($($t :tt ) ,*) ) =>{($(read_value !($iter ,$t ) ) ,*) } ;($iter :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($iter ,$t ) ) .collect ::<Vec <_ >>() } ;($iter :expr ,{chars :$base :expr } ) =>{read_value !($iter ,String ) .chars () .map (|c |(c as u8 -$base as u8 ) as usize ) .collect ::<Vec <usize >>() } ;($iter :expr ,{char :$base :expr } ) =>{read_value !($iter ,{chars :$base } ) [0 ] } ;($iter :expr ,chars ) =>{read_value !($iter ,String ) .chars () .collect ::<Vec <char >>() } ;($iter :expr ,char ) =>{read_value !($iter ,chars ) [0 ] } ;($iter :expr ,usize1 ) =>{read_value !($iter ,usize ) -1 } ;($iter :expr ,$t :ty ) =>{$iter .next () .unwrap () .parse ::<$t >() .unwrap () } ;}
macro_rules !input_inner {($iter :expr ) =>{} ;($iter :expr ,) =>{} ;($iter :expr ,mut $var :ident :$t :tt $($r :tt ) *) =>{let mut $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,mut $var :ident $($r :tt ) *) =>{input_inner !{$iter ,mut $var :usize $($r ) *} } ;($iter :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,$var :ident $($r :tt ) *) =>{input_inner !{$iter ,$var :usize $($r ) *} } ;}
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;(iter =$iter :ident ,$($r :tt ) *) =>{let s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut $iter =s .split_whitespace () ;input_inner !{$iter ,$($r ) *} } ;($($r :tt ) *) =>{let s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut iter =s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;}
pub trait Bisect: Copy {
    fn halve(self, other: Self) -> Self;
    fn section_end(self, other: Self) -> bool;
}
pub mod bisect_impl {
    use super::*;
    macro_rules! impl_bisect_unsigned {
        ($t :ty ) => {
            impl Bisect for $t {
                fn halve(self, other: Self) -> Self {
                    if self > other {
                        other + (self - other) / 2
                    } else {
                        self + (other - self) / 2
                    }
                }
                fn section_end(self, other: Self) -> bool {
                    (if self > other {
                        self - other
                    } else {
                        other - self
                    }) <= 1
                }
            }
        };
    }
    macro_rules! impl_bisect_signed {
        ($t :ty ) => {
            impl Bisect for $t {
                fn halve(self, other: Self) -> Self {
                    (self + other) / 2
                }
                fn section_end(self, other: Self) -> bool {
                    (self - other).abs() <= 1
                }
            }
        };
    }
    macro_rules! impl_bisect_float {
        ($t :ty ) => {
            impl Bisect for $t {
                fn halve(self, other: Self) -> Self {
                    (self + other) / 2.
                }
                fn section_end(self, other: Self) -> bool {
                    (self - other).abs() <= 1e-8
                }
            }
        };
    }
    impl_bisect_unsigned!(u8);
    impl_bisect_unsigned!(u16);
    impl_bisect_unsigned!(u32);
    impl_bisect_unsigned!(u64);
    impl_bisect_unsigned!(usize);
    impl_bisect_signed!(i8);
    impl_bisect_signed!(i16);
    impl_bisect_signed!(i32);
    impl_bisect_signed!(i64);
    impl_bisect_signed!(isize);
    impl_bisect_float!(f32);
    impl_bisect_float!(f64);
}
pub fn binary_search<T: Bisect, F: Fn(T) -> bool>(f: F, ok: T, err: T) -> T {
    let mut ok = ok;
    let mut err = err;
    while !ok.section_end(err) {
        let m = ok.halve(err);
        if f(m) {
            ok = m;
        } else {
            err = m;
        }
    }
    ok
}
pub fn lower_bound<T: Bisect + Ord>(v: &[T], x: T) -> usize {
    binary_search(|i| v[i as usize] >= x, v.len() as i64, -1) as usize
}
pub fn upper_bound<T: Bisect + Ord>(v: &[T], x: T) -> usize {
    binary_search(|i| v[i as usize] > x, v.len() as i64, -1) as usize
}
#[derive(Clone, Debug)]
pub struct Compress<T> {
    v: Vec<T>,
}
impl<T: Bisect + Ord> Compress<T> {
    pub fn get(&self, x: T) -> usize {
        lower_bound(&self.v, x)
    }
}
impl<T> Compress<T> {
    pub fn len(&self) -> usize {
        self.v.len()
    }
}
impl<T> std::ops::Index<usize> for Compress<T> {
    type Output = T;
    fn index(&self, index: usize) -> &Self::Output {
        &self.v[index]
    }
}
impl<T: Ord> std::iter::FromIterator<T> for Compress<T> {
    fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Compress<T> {
        use std::collections::BTreeSet;
        let v = iter
            .into_iter()
            .collect::<BTreeSet<T>>()
            .into_iter()
            .collect::<Vec<T>>();
        Compress { v }
    }
}
pub struct GridGraph {
    height: usize,
    width: usize,
}
impl GridGraph {
    pub fn new(height: usize, width: usize) -> Self {
        Self { height, width }
    }
    pub fn len_adjacency(&self, x: usize, y: usize) -> usize {
        (x + 1 < self.height) as usize
            + (y + 1 < self.width) as usize
            + (x > 0) as usize
            + (y > 0) as usize
    }
    pub fn for_each_adjacency<F: FnMut(usize, usize)>(&self, x: usize, y: usize, mut f: F) {
        if x + 1 < self.height {
            f(x + 1, y);
        }
        if y + 1 < self.width {
            f(x, y + 1);
        }
        if x > 0 {
            f(x - 1, y);
        }
        if y > 0 {
            f(x, y - 1);
        }
    }
}
fn main() {
    input!(n, m, abc: [(i64, i64, i64); n], def: [(i64, i64, i64); m]);
    let mut ans = 0i64;
    let mut xs = vec![-1_001_001_001, 0, 1_001_001_001];
    let mut ys = vec![-1_001_001_001, 0, 1_001_001_001];
    for &(a, b, c) in &abc {
        xs.push(a);
        xs.push(b);
        ys.push(c);
    }
    for &(d, e, f) in &def {
        xs.push(d);
        ys.push(e);
        ys.push(f);
    }
    let xs: Compress<_> = xs.into_iter().collect();
    let ys: Compress<_> = ys.into_iter().collect();
    let h = xs.len();
    let w = ys.len();
    let mut vis = vec![vec![false; w * 2 - 1]; h * 2 - 1];
    let mut on = vec![vec![false; w * 2 - 1]; h * 2 - 1];
    for &(a, b, c) in abc.iter() {
        let x1 = xs.get(a) * 2;
        let x2 = xs.get(b) * 2;
        let y = ys.get(c) * 2;
        for i in x1..=x2 {
            on[i][y] = true;
        }
    }
    for &(d, e, f) in def.iter() {
        let x = xs.get(d) * 2;
        let y1 = ys.get(e) * 2;
        let y2 = ys.get(f) * 2;
        for j in y1..=y2 {
            on[x][j] = true;
        }
    }
    let gg = GridGraph::new(h * 2 - 1, w * 2 - 1);
    let (s, t) = (xs.get(0) * 2, ys.get(0) * 2);
    vis[s][t] = true;
    let mut que = std::collections::VecDeque::new();
    que.push_back((s, t));
    while let Some((s, t)) = que.pop_front() {
        if s % 2 == 1 && t % 2 == 1 && vis[s][t] {
            ans += (xs[s / 2 + 1] - xs[s / 2]) * (ys[t / 2 + 1] - ys[t / 2]);
        }
        if gg.len_adjacency(s, t) < 4 {
            println!("INF");
            std::process::exit(0);
        }
        gg.for_each_adjacency(s, t, |x, y| {
            if !vis[x][y] && !on[x][y] {
                vis[x][y] = true;
                que.push_back((x, y))
            }
        });
    }
    println!("{}", ans);
}


Measured memory_bytes: 73136