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

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

vector<int> compress (vector<int> a) {
    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());
    return a;
}

int main() {
    int n, m;
    cin >> n >> m;
    // key : 座圧前, value : 座圧後
    map<int, int> datx, daty;
    datx[0] = 0; daty[0] = 0;

    vector<int> a(n), b(n), c(n), d(m), e(m), f(m);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> c[i];
        datx[a[i]] = 0;
        datx[b[i]] = 0;
        daty[c[i]] = 0;
    }
    for (int i = 0; i < m; i++) {
        cin >> d[i] >> e[i] >> f[i];
        datx[d[i]] = 0;
        daty[e[i]] = 0;
        daty[f[i]] = 0;
    }

    // index : 座圧後, value : 座圧前
    vector<int> cx, cy;
    for (auto &e : datx) {
        e.second = cx.size();
        cx.push_back(e.first);
    }
    for (auto &e : daty) {
        e.second = cy.size();
        cy.push_back(e.first);
    }

    const int h = cx.size() * 2;
    const int w = cy.size() * 2;
    // 0 : 未到達, 1 : 到達済み, 2 : 壁
    vector<vector<int>> g(h, vector<int>(w, 0));
    for (int i = 0; i < n; i++) {
        int y = daty[c[i]] * 2;
        int from = datx[a[i]] * 2, to = datx[b[i]] * 2;
        for (int x = from; x <= to; x++) g[x][y] = 2;
    }
    for (int i = 0; i < m; i++) {
        int x = datx[d[i]] * 2;
        int from = daty[e[i]] * 2, to = daty[f[i]] * 2;
        for (int y = from; y <= to; y++) g[x][y] = 2;
    }

    queue<pair<int, int>> que;
    que.emplace(datx[0] * 2, daty[0] * 2);
    while (not que.empty()) {
        auto [x, y] = que.front(); que.pop();
        if (g[x][y] != 0) continue;
        g[x][y] = 1;
        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx < 0 or h <= nx or ny < 0 or w <= ny) continue;
            if (g[nx][ny] != 0) continue;
            que.emplace(nx, ny);
        }
    }

    long long ans = 0;
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
        if (g[i][j] != 1) continue;
        if (i == 0 or i + 1 == h or j == 0 or j + 1 == w) {
            cout << "INF" << '\n';
            return 0;
        }
        if (i % 2 == 0 or j % 2 == 0) continue;
        long long x = cx[i / 2 + 1] - cx[i / 2];
        long long y = cy[j / 2 + 1] - cy[j / 2];
        ans += x * y;
    }
    
    cout << ans << '\n';

    return 0;
}