#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

ll ans = 0;

char u[7000][7000];

vector<int> xx, yy;

struct Grid {
    Grid(int h, int w) : h(h), w(w), st(w + 1), v(h * st, -1) {}
    int p(int i, int j) const {
        return st * i + j;
    }
    void bfs(int k) {
        queue<int> q;
        q.push(k);
        v[k] = 0;
        while (!q.empty()) {
            int k = q.front(); q.pop();
            for (int d : { -st, -1, 1, st }) {
                int l = k + d;
                int i = l / st;
                int j = l % st;
                if (l < 0 || i == h || j == w) continue;
                if (v[l] < 0 && u[i][j] == 0) {
                    q.push(l);
                    v[l] = v[k] + 1;
                    if (i == 6900 && j == 6900) {
                        cout << "INF" << endl;
                        exit(0);
                    }
                    if (i % 2 && j % 2) {
                        i = i / 2 - 1;
                        j = j / 2 - 1;
                        if (i < 0 || i >= (int)xx.size()) continue;
                        if (j < 0 || j >= (int)yy.size()) continue;
                        int x = xx[i];
                        int y = yy[j];
                        ans += (ll)x * y;
                    }
                }
            }
        }
    }
    int h, w, st;
    vector<int> v;
};

struct P {
    int a, b, c;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    vector<P> p(n + m);
    vector<pair<int, int>> x(n * 2 + m + 1), y(m * 2 + n + 1);
    for (int i = 0; i < n; i++) {
        int a, b, c;
        cin >> a >> b >> c;

        x[i * 2 + 0] = { a, i * 2 + 0 };
        x[i * 2 + 1] = { b, i * 2 + 1 };
        y[m * 2 + i] = { c, m * 2 + i };
    }
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;

        y[i * 2 + 0] = { b, i * 2 + 0 };
        y[i * 2 + 1] = { c, i * 2 + 1 };
        x[n * 2 + i] = { a, n * 2 + i };
    }
    x[n * 2 + m] = { 0, n * 2 + m };
    y[m * 2 + n] = { 0, m * 2 + n };

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    int k = 1, a, b;
    for (int i = 0; i < n * 2 + m + 1; i++) {
        if (i > 0 && x[i].first != x[i - 1].first) {
            xx.push_back(x[i].first - x[i - 1].first);
            k++;
        }
        int j = x[i].second;
        if (j < n * 2) {
            (j % 2 == 0 ? p[j / 2].a : p[j / 2].b) = k;
        } else if (j < n * 2 + m) {
            p[n + j - n * 2].a = k;
        } else {
            a = k;
        }
    }
    k = 1;
    for (int i = 0; i < m * 2 + n + 1; i++) {
        if (i > 0 && y[i].first != y[i - 1].first) {
            yy.push_back(y[i].first - y[i - 1].first);
            k++;
        }
        int j = y[i].second;
        if (j < m * 2) {
            (j % 2 == 0 ? p[n + j / 2].b : p[n + j / 2].c) = k;
        } else if (j < m * 2 + n) {
            p[j - m * 2].c = k;
        } else {
            b = k;
        }
    }

    for (int i = 0; i < n; i++) {
        auto [a, b, c] = p[i];
        for (int j = a * 2; j <= b * 2; j++) {
            u[j][c * 2] = 1;
        }
    }
    for (int i = 0; i < m; i++) {
        auto [a, b, c] = p[n + i];
        for (int j = b * 2; j <= c * 2; j++) {
            u[a * 2][j] = 1;
        }
    }

    Grid g(7000, 7000);
    g.bfs(g.p(a * 2, b * 2));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 235720