/* #region Head */

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pll = pair<ll, ll>;
template <class T> using vc = vector<T>;
template <class T> using vvc = vc<vc<T>>;
using vll = vc<ll>;
using vvll = vvc<ll>;
using vld = vc<ld>;
using vvld = vvc<ld>;
using vs = vc<string>;
using vvs = vvc<string>;
template <class T, class U> using um = unordered_map<T, U>;
template <class T> using pq = priority_queue<T>;
template <class T> using pqa = priority_queue<T, vc<T>, greater<T>>;
template <class T> using us = unordered_set<T>;

#define REP(i, m, n) for (ll i = (m), i##_len = (ll)(n); i < i##_len; ++(i))
#define REPM(i, m, n) for (ll i = (m), i##_max = (ll)(n); i <= i##_max; ++(i))
#define REPR(i, m, n) for (ll i = (m), i##_min = (ll)(n); i >= i##_min; --(i))
#define REPD(i, m, n, d) for (ll i = (m), i##_len = (ll)(n); i < i##_len; i += (d))
#define REPMD(i, m, n, d) for (ll i = (m), i##_max = (ll)(n); i <= i##_max; i += (d))
#define REPI(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define ALL(x) begin(x), end(x)
#define SIZE(x) ((ll)(x).size())
#define PERM(c)                                                                                                        \
    sort(ALL(c));                                                                                                      \
    for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))
#define UNIQ(v) v.erase(unique(ALL(v)), v.end());

#define endl '\n'
#define sqrt sqrtl
#define floor floorl
#define log2 log2l

constexpr ll INF = 1'010'000'000'000'000'017LL;
constexpr ll MOD = 1'000'000'007LL; // 1e9 + 7
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.14159265358979323846;

template <typename T> istream &operator>>(istream &is, vc<T> &vec) { // vector 入力
    for (T &x : vec) is >> x;
    return is;
}
template <typename T> ostream &operator<<(ostream &os, vc<T> &vec) { // vector 出力 (for dump)
    os << "{";
    REP(i, 0, SIZE(vec)) os << vec[i] << (i == i_len - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T> ostream &operator>>(ostream &os, vc<T> &vec) { // vector 出力 (inline)
    REP(i, 0, SIZE(vec)) os << vec[i] << (i == i_len - 1 ? "\n" : " ");
    return os;
}

template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &pair_var) { // pair 入力
    is >> pair_var.first >> pair_var.second;
    return is;
}
template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { // pair 出力
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}

// map, um, set, us 出力
template <class T> ostream &out_iter(ostream &os, T &map_var) {
    os << "{";
    REPI(itr, map_var) {
        os << *itr;
        auto itrcp = itr;
        if (++itrcp != map_var.end()) os << ", ";
    }
    return os << "}";
}
template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { return out_iter(os, map_var); }
template <typename T, typename U> ostream &operator<<(ostream &os, um<T, U> &map_var) { return out_iter(os, map_var); }
template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) { return out_iter(os, set_var); }
template <typename T> ostream &operator<<(ostream &os, us<T> &set_var) { return out_iter(os, set_var); }
template <typename T> ostream &operator<<(ostream &os, pq<T> &pq_var) {
    pq<T> pq_cp(pq_var);
    os << "{";
    if (!pq_cp.empty()) {
        os << pq_cp.top(), pq_cp.pop();
        while (!pq_cp.empty()) os << ", " << pq_cp.top(), pq_cp.pop();
    }
    return os << "}";
}

// dump
#define DUMPOUT cerr
void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) DUMPOUT << ", ";
    dump_func(move(tail)...);
}

// chmax (更新「される」かもしれない値が前)
template <typename T, typename U, typename Comp = less<>> bool chmax(T &xmax, const U &x, Comp comp = {}) {
    if (comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

// chmin (更新「される」かもしれない値が前)
template <typename T, typename U, typename Comp = less<>> bool chmin(T &xmin, const U &x, Comp comp = {}) {
    if (comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// ローカル用
#define DEBUG_

#ifdef DEBUG_
#define DEB
#define dump(...)                                                                                                      \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                                                                    \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl                                        \
            << "    ",                                                                                                 \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

struct AtCoderInitialize {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    AtCoderInitialize() {
        ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
        cout << fixed << setprecision(IOS_PREC);
        if (AUTOFLUSH) cout << unitbuf;
    }
} ATCODER_INITIALIZE;

string yes = "Yes", no = "No";
// string yes = "YES", no = "NO";
void yn(bool p) { cout << (p ? yes : no) << endl; }

/* #endregion */

/* #region CoordCompress1DLined */

// 幅 0 の点で領域が分けられる場合の 1 次元座圧
class CoordCompress1DLined {
    um<ll, ll> coord2zipped_point; // キーが座標値，点の通常座標→圧縮座標
    vll zipped2coord;              // 各要素が座標値，点or区画の圧縮座標→通常座標
    ll sz;

  public:
    CoordCompress1DLined() {}
    // 点の座標から座圧クラスを初期化する
    CoordCompress1DLined(vll coords) {
        sort(ALL(coords));
        UNIQ(coords); // 点の座標たち
        // sz = SIZE(coords);
        ll mi = *min_element(ALL(coords));         // 最左点
        vll coords_expanded(2 * SIZE(coords) + 1); // [l, l+1) の区画を「区画l」とする
        coords_expanded[0] = mi - 1;
        // 区画mi-1, 点mi, 区画mi, 点mi+1, 区画mi+1, ..., 点max, 区画max
        REP(i, 0, SIZE(coords)) coords_expanded[2 * i + 1] = coords_expanded[2 * i + 2] = coords[i];
        sz = SIZE(coords_expanded);
        zipped2coord = coords_expanded;
        REP(i, 0, SIZE(coords)) coord2zipped_point[coords_expanded[2 * i + 1]] = 2 * i + 1;
    }
    // 点の座標の圧縮
    ll zip(ll coord) { return coord2zipped_point[coord]; }
    // 点・区画の座標の解凍
    ll unzip(ll zipped) { return zipped2coord[zipped]; }
    // 座圧後の要素数を返す
    ll size() { return sz; }

    // 区画の長さを返す，区画でなく点の場合は 0
    ll length(ll zipped) {
        if (zipped % 2 == 1) return 0;                   // 点
        if (zipped == 0 || zipped == sz - 1) return INF; // 端の区画
        return unzip(zipped + 1) - unzip(zipped);
    }

    // その点が入る領域 or 点の圧縮座標を返す,
    // point=false なら，coord をマス名として扱い，そのマスを含む区画の圧縮座標を返す．
    ll zip_leq(ll coord, bool point = false) {
        auto rit = lower_bound(zipped2coord.rbegin(), zipped2coord.rend(), coord,
                               [](ll const lhs, ll const rhs) { return lhs > rhs; });
        if (rit != zipped2coord.rend()) {
            return (point && *rit == coord) ? zip(coord) : zip(*rit) + 1;
        }
        return -INF;
    }
};

/* #endregion */

/* #region CoordCompress2DLined */

// 幅 0 の線が引かれる場合の 2 次元座圧
// 各区画は，点・線・長方形のいずれかを表す
class CoordCompress2DLined {
    CoordCompress1DLined axis_x, axis_y;

  public:
    CoordCompress2DLined(vll coordsX, vll coordsY) : axis_x(coordsX), axis_y(coordsY) {}

    // 点の座標の圧縮
    pll zip(ll coord_x, ll coord_y) { return {axis_x.zip(coord_x), axis_y.zip(coord_y)}; }
    // 点・区画の座標の解凍
    pll unzip(ll zipped_x, ll zipped_y) { return {axis_x.unzip(zipped_x), axis_y.unzip(zipped_y)}; }
    // 区画の面積
    ll area(ll zipped_x, ll zipped_y) {
        if (zipped_x <= 0 || zipped_y <= 0 || zipped_x + 1 >= axis_x.size() || zipped_y + 1 >= axis_y.size()) {
            return INF;
        }
        return axis_x.length(zipped_x) * axis_y.length(zipped_y);
    }
    // その点が入る領域 or 点の圧縮座標を返す,
    // point=false なら，coord をマス名として扱い，そのマスを含む区画の圧縮座標を返す．
    pll zip_leq(ll coord_x, ll coord_y, bool point = false) {
        return {axis_x.zip_leq(coord_x), axis_y.zip_leq(coord_y)};
    }

    pll size() { return {axis_x.size(), axis_y.size()}; }
};

/* #endregion */

// Problem
void solve() {
    ll n, m;
    cin >> n >> m;
    vll a(n), b(n), c(n), d(m), e(m), f(m);
    REP(i, 0, n) cin >> a[i] >> b[i] >> c[i];
    REP(i, 0, m) cin >> d[i] >> e[i] >> f[i];

    vll x = a, y = c;
    x.insert(x.end(), ALL(b)), x.insert(x.end(), ALL(d));
    y.insert(y.end(), ALL(e)), y.insert(y.end(), ALL(f));

    CoordCompress2DLined cc(x, y);

    auto [sx, sy] = cc.size();
    vc<vc<bool>> visited(sx, vc<bool>(sy, false));

    REP(i, 0, n) { // 訪問不可能な部分を塗る
        ll x_start = min(a[i], b[i]), x_terminal = max(a[i], b[i]);
        auto [zipped_x_start, zipped_y] = cc.zip(x_start, c[i]);
        auto [zipped_x_terminal, _] = cc.zip(x_terminal, c[i]);
        REPM(zipped_x, zipped_x_start, zipped_x_terminal) visited[zipped_x][zipped_y] = true;
    }
    REP(i, 0, m) { // 訪問不可能な部分を塗る
        ll y_start = min(e[i], f[i]), y_terminal = max(e[i], f[i]);
        auto [zipped_x, zipped_y_start] = cc.zip(d[i], y_start);
        auto [_, zipped_y_terminal] = cc.zip(d[i], y_terminal);
        REPM(zipped_y, zipped_y_start, zipped_y_terminal) visited[zipped_x][zipped_y] = true;
    }

    // debug
    // REP(i, 0, sx) {
    //     REP(j, 0, sy) cout << (visited[i][j] ? '#' : '.');
    //     cout << endl;
    // }

    const int dx[4] = {1, 0, -1, 0};
    const int dy[4] = {0, 1, 0, -1};
    ll surface = 0;
    ll sx_ = sx, sy_ = sy; // 構造化束縛はキャプチャできないため
    auto dfs = [&](auto &&dfs, ll zipped_x, ll zipped_y) -> void {
        // if (visited[zipped_x][zipped_y]) return;
        visited[zipped_x][zipped_y] = true;
        ll area = cc.area(zipped_x, zipped_y);
        // dump(zipped_x, zipped_y, area);
        if (area == INF) {
            cout << "INF" << endl;
            exit(0);
        }
        surface += area;
        REP(dir, 0, 4) {
            ll zipped_x_next = zipped_x + dx[dir];
            ll zipped_y_next = zipped_y + dy[dir];

            if (zipped_x_next < 0 || zipped_x_next >= sx_ || zipped_y_next < 0 || zipped_y_next >= sy_) continue;
            if (visited[zipped_x_next][zipped_y_next]) continue;
            dfs(dfs, zipped_x_next, zipped_y_next);
        }
    };
    auto [zipped_x_origin, zipped_y_origin] = cc.zip(0, 0);
    dfs(dfs, zipped_x_origin, zipped_y_origin);
    cout << surface << endl;
}

// entry point
int main() {
    solve();
    return 0;
}
