#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;


constexpr int64_t INF = 1e18;
int64_t solve(int n, int m, const vector<int64_t> & a, const vector<int64_t> & b, const vector<int64_t> & c, const vector<int64_t> & d, const vector<int64_t> & e, const vector<int64_t> & f) {
    vector<int64_t> ys;
    ys.insert(ys.end(), ALL(c));
    ys.insert(ys.end(), ALL(e));
    ys.insert(ys.end(), ALL(f));
    ys.push_back(-INF);
    ys.push_back(0);
    ys.push_back(INF);
    sort(ALL(ys));
    ys.erase(unique(ALL(ys)), ys.end());

    vector<int64_t> xs;
    xs.insert(xs.end(), ALL(a));
    xs.insert(xs.end(), ALL(b));
    xs.insert(xs.end(), ALL(d));
    xs.push_back(-INF);
    xs.push_back(0);
    xs.push_back(INF);
    sort(ALL(xs));
    xs.erase(unique(ALL(xs)), xs.end());

    int h = ys.size() - 1;
    int w = xs.size() - 1;
    vector<vector<char> > dist(2 * h - 1, vector<char>(2 * w - 1, '.'));
    REP (i, n) {
        int a_i = (lower_bound(ALL(xs), a[i]) - xs.begin()) * 2 - 1;
        int b_i = (lower_bound(ALL(xs), b[i]) - xs.begin()) * 2 - 1;
        int c_i = (lower_bound(ALL(ys), c[i]) - ys.begin()) * 2 - 1;
        REP3 (x, a_i, b_i + 1) {
            dist[c_i][x] = '#';
        }
    }
    REP (i, m) {
        int d_i = (lower_bound(ALL(xs), d[i]) - xs.begin()) * 2 - 1;
        int e_i = (lower_bound(ALL(ys), e[i]) - ys.begin()) * 2 - 1;
        int f_i = (lower_bound(ALL(ys), f[i]) - ys.begin()) * 2 - 1;
        REP3 (y, e_i, f_i + 1) {
            dist[y][d_i] = '#';
        }
    }

    stack<pair<int, int> > stk;
    int y = (lower_bound(ALL(ys), 0) - ys.begin()) * 2 - 1;
    int x = (lower_bound(ALL(xs), 0) - xs.begin()) * 2 - 1;
    dist[y][x] = '*';
    stk.emplace(y, x);
    while (not stk.empty()) {
        auto [y, x] = stk.top();
        stk.pop();
        REP (i, 4) {
            int ny = y + (i - 2) % 2;
            int nx = x + (i - 1) % 2;
            if (ny < 0 or 2 * h - 1 <= ny or nx < 0 or 2 * w - 1 <= nx) {
                return INF;
            }
            if (dist[ny][nx] == '.') {
                dist[ny][nx] = '*';
                stk.emplace(ny, nx);
            }
        }
    }

    int64_t ans = 0;
    REP (y, 2 * h - 1) if (y % 2 == 0) {
        REP (x, 2 * w - 1) if (x % 2 == 0 and dist[y][x] == '*') {
            int64_t dy = ys[y / 2 + 1] - ys[y / 2];
            int64_t dx = xs[x / 2 + 1] - xs[x / 2];
            ans += dy * dx;
        }
    }
    return ans;
}

// generated by online-judge-template-generator v4.1.0 (https://github.com/kmyk/online-judge-template-generator)
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    constexpr char endl = '\n';
    int N, M;
    cin >> N;
    vector<int64_t> A(N), B(N), C(N);
    cin >> M;
    vector<int64_t> D(M), E(M), F(M);
    REP (i, N) {
        cin >> A[i] >> B[i] >> C[i];
    }
    REP (i, M) {
        cin >> D[i] >> E[i] >> F[i];
    }
    auto ans = solve(N, M, A, B, C, D, E, F);
    if (ans == INF) {
        cout << "INF" << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 118776