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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define INF 1125899906842624

struct Line {
    i64 a, b, c;
    Line(i64 a, i64 b, i64 c) : a(a), b(b), c(c) {}
};

i64 dy[4] = {1, 0, -1, 0};
i64 dx[4] = {0, 1, 0, -1};

int main() {
    i64 N, M; cin >> N >> M;
    vector<Line> lv, lh;
    map<i64, i64> mpX;
    map<i64, i64> mpY;
    mpX[0] = 0, mpY[0] = 0;
    REP(i, N) {
        i64 a, b, c; cin >> a >> b >> c;
        lv.emplace_back(a, b, c);
        mpY[a] = 0, mpY[b] = 0, mpX[c] = 0;
    }
    REP(i, M) {
        i64 a, b, c; cin >> a >> b >> c;
        lh.emplace_back(b, c, a);
        mpY[a] = 0, mpX[b] = 0, mpX[c] = 0;
    }
    vector<i64> yvals;
    vector<i64> xvals;
    for (auto &p : mpY) {
        p.second = yvals.size();
        yvals.pb(p.first);
    }
    for (auto &p : mpX) {
        p.second = xvals.size();
        xvals.pb(p.first);
    }

    i64 h = yvals.size() * 2;
    i64 w = xvals.size() * 2;
    vector<vector<i64>> G(h, vector<i64>(w, 0));
    for (Line &line : lv) {
        i64 ys = mpY[line.a] * 2;
        i64 ye = mpY[line.b] * 2;
        i64 x = mpX[line.c] * 2;
        for (i64 y = ys; y <= ye; y++) {
            G[y][x] = -1;
        }
    }
    for (Line &line : lh) {
        i64 xs = mpX[line.a] * 2;
        i64 xe = mpX[line.b] * 2;
        i64 y = mpY[line.c] * 2;
        for (i64 x = xs; x <= xe; x++) {
            G[y][x] = -1;
        }
    }

    // REP(y, h) {
    //     REP(x, w) cout << setw(2) << G[y][x] << " ";
    //     cout << endl;
    // }

    using P = pair<i64, i64>;
    vector<vector<i64>> d(h, vector<i64>(w, -1));
    queue<P> que;
    i64 sy, sx;
    sy = mpY[0] * 2, sx = mpX[0] * 2;
    d[sy][sx] = 0;
    G[sy][sx] = 1;
    que.emplace(sy, sx);
    while(!que.empty()) {
        P p = que.front(); que.pop();
        REP(i, 4) {
            i64 ny = p.first + dy[i];
            i64 nx = p.second + dx[i];
            if (ny < 0 || ny >= h || nx < 0 || nx >= w) {
                cout << "INF" << endl;
                return 0;
            }
            if (G[ny][nx] == -1) continue;
            if (d[ny][nx] == -1) {
                G[ny][nx] = 1;
                d[ny][nx] = d[p.first][p.second] + 1;
                que.emplace(ny, nx);
            }
        }
    }

    i64 ans = 0;
    REP(y, h) {
        REP(x, w) {
            if (y % 2 == 0 || x % 2 == 0) continue;
            if (G[y][x] != 1) continue;
            ans += (yvals[y / 2 + 1] - yvals[y / 2]) * (xvals[x / 2 + 1] - xvals[x / 2]);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 567096