#include <limits>
#include <initializer_list>
#include <utility>
#include <bitset>
#include <tuple>
#include <type_traits>
#include <functional>
#include <string>
#include <array>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <algorithm>
#include <complex>
#include <random>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <regex>
#include <cassert>
#include <cstddef>
#include <variant>

// Yay!!
#define endl codeforces

// macros for iterator
#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)

// alias
using ll = std::int64_t;
using ull = std::uint64_t;
using pii = std::pair<int, int>;
using tii = std::tuple<int, int, int>;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;

// variadic min/max
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }

// variadic chmin/chmax
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }

// multi demension array
template <typename T, std::size_t Head, std::size_t... Tail> struct multi_dim_array { using type = std::array<typename multi_dim_array<T, Tail...>::type, Head>; };
template <typename T, std::size_t Head> struct multi_dim_array<T, Head> { using type = std::array<T, Head>; };
template <typename T, std::size_t... Args> using mdarray = typename multi_dim_array<T, Args...>::type;

// fill container
template <typename T, typename F, typename... Args> 
void fill_seq(T &t, F f, Args... args) { if constexpr (std::is_invocable<F, Args...>::value) { t = f(args...); } else { for (ssize_t i = 0; i < t.size(); i++) fill_seq(t[i], f, args..., i); } }

// make multi dimension vector
template <typename T> vec<T> make_v(ssize_t sz) { return vec<T>(sz); }
template <typename T, typename... Tail> auto make_v(ssize_t hs, Tail&&... ts) { auto v = std::move(make_v<T>(std::forward<Tail>(ts)...)); return vec<decltype(v)>(hs, v); }

// init
namespace init__ { 
struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; 
}


namespace tree {

struct UnionFind {
    vec<ll> rank, par;
    vec<ssize_t> sz;

    UnionFind(ll n) : rank(n), par(n), sz(n) {
        init();
    }

    void init() {
        std::fill(ALL(rank), 1);
        std::iota(ALL(par), 0);
        std::fill(ALL(sz), 1);
    }

    ll find(ll n) {
        return (n == par[n] ? n : par[n] = find(par[n]));
    }

    bool unit(ll x, ll y) {
        ll px = find(x), py = find(y);
        if (px == py) return false;
        if (rank[px] < rank[py]) std::swap(px, py);
        par[py] = px;
        rank[px] += (rank[px] == rank[py]);
        sz[px] += sz[py];
        return true;
    }

    bool same(ll x, ll y) {
        return find(x) == find(y);
    }

    ssize_t size(ll n) {
        return sz[find(n)];
    }
};

}

struct CompressVtx {
    vec<ll> v;
    CompressVtx(const vec<ll> &arg) : v(arg) {
        std::sort(ALL(v));
        v.erase(std::unique(ALL(v)), v.end());
    }

    ll get(ll x) {
        return std::distance(v.begin(),
                             std::lower_bound(ALL(v), x));
    }

    ll value(ll idx) {
        return v[idx];
    }
};

void input(vec<tll> &v) {
    for (auto &&e : v) {
        ll a, b, c;
        std::cin >> a >> b >> c;
        e = tll(a, b, c);
    }
}

const ll inf = 5e15;

int main() {
    ll n, m;
    std::cin >> n >> m;
    vec<tll> xl(n), yl(m);
    input(xl);
    input(yl);

    vec<ll> xv = { -inf, 0, inf, }, yv = { -inf, 0, inf, };
    for (auto &&e : xl) {
        auto [ a, b, c ] = e;
        xv.push_back(a);
        xv.push_back(b);
        yv.push_back(c);
    }
    for (auto &&e : yl) {
        auto [ a, b, c ] = e;
        xv.push_back(a);
        yv.push_back(b);
        yv.push_back(c);
    }

    CompressVtx cx(xv), cy(yv);
    ll xsz = cx.v.size(), ysz = cy.v.size();
    auto imosh = make_v<ll>(ysz, xsz + 1);  // hline
    auto imosv = make_v<ll>(xsz, ysz + 1);  // vline
    fill_seq(imosh, [](int, int) { return 0; });
    fill_seq(imosv, [](int, int) { return 0; });
    for (auto &&e : xl) {
        auto [ a, b, c ] = e;
        ll yid = cy.get(c);
        ll x1 = cx.get(a), x2 = cx.get(b);
        imosh[yid][x1]++;
        imosh[yid][x2]--;
    }
    for (auto &&e : yl) {
        auto [ a, b, c ] = e;
        ll xid = cx.get(a);
        ll y1 = cy.get(b), y2 = cy.get(c);
        imosv[xid][y1]++;
        imosv[xid][y2]--;
    }
    for (auto &&v : imosh) for (ll i = 0; i + 1 < v.size(); i++) v[i + 1] += v[i];
    for (auto &&v : imosv) for (ll i = 0; i + 1 < v.size(); i++) v[i + 1] += v[i];

    tree::UnionFind uf(xsz * ysz + 10);
    auto make_id = [&](ll xid, ll yid) {
        return xid * ysz + yid;
    };

    for (ll xidx = 0; xidx + 1 < xsz; xidx++) for (ll yidx = 0; yidx + 1 < ysz; yidx++) {
        ll x1 = xidx, x2 = xidx + 1;
        ll y1 = yidx, y2 = yidx + 1;
        if (!imosh[y2][x1]) uf.unit(make_id(x1, y1), make_id(x1, y2));
        if (!imosv[x2][y1]) uf.unit(make_id(x1, y1), make_id(x2, y1));
    }

    auto x0 = cx.get(0), y0 = cy.get(0);
    ll id0 = make_id(x0, y0);
    ll ans = 0;
    for (ll xidx = 0; xidx + 1 < xsz; xidx++) for (ll yidx = 0; yidx + 1 < ysz; yidx++) {
        ll x1 = cx.value(xidx), x2 = cx.value(xidx + 1);
        ll y1 = cy.value(yidx), y2 = cy.value(yidx + 1);
        ll id = make_id(xidx, yidx);
        if (!uf.same(id0, id)) continue;
        if (std::abs(x1) == inf || std::abs(x2) == inf || 
            std::abs(y1) == inf || std::abs(y2) == inf) {
            std::cout << "INF\n";
            return 0;
        }
        ans += (x2 - x1) * (y2 - y1);
    }

    std::cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 355912